diff --git a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Commandlet/CookAssetsCommandlet.cpp b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Commandlet/CookAssetsCommandlet.cpp index b3d642545..6c182e321 100644 --- a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Commandlet/CookAssetsCommandlet.cpp +++ b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Commandlet/CookAssetsCommandlet.cpp @@ -165,21 +165,29 @@ bool UCookAssetsCommandlet::SaveWorld( // Check if OpenDrive file exists FString PathXODR = FPaths::ProjectContentDir() + PackageName + TEXT("/Maps/") + WorldName + TEXT( "/OpenDrive/") + WorldName + TEXT(".xodr"); + + bool bPackageSaved = false; if (FPaths::FileExists(PathXODR)) { // Filling the map stuff (Code only applied for maps) AOpenDriveActor *OpenWorldActor = CastChecked(World->SpawnActor(AOpenDriveActor::StaticClass(), new FVector(), NULL)); + OpenWorldActor->BuildRoutes(WorldName); OpenWorldActor->AddSpawners(); - } - // Saving the package - FString PackageFileName = FPackageName::LongPackageNameToFilename(PackagePath, - FPackageName::GetMapPackageExtension()); - return UPackage::SavePackage(Package, World, EObjectFlags::RF_Public | EObjectFlags::RF_Standalone, - *PackageFileName, GError, nullptr, true, true, SAVE_NoError); + SavePackage(PackagePath, Package); + + OpenWorldActor->RemoveRoutes(); + OpenWorldActor->RemoveSpawners(); + OpenWorldActor->Destroy(); + } + else + { + SavePackage(PackagePath, Package); + } + return bPackageSaved; } FAssetsPaths UCookAssetsCommandlet::GetAssetsPathFromPackage(const FString &PackageName) const @@ -254,6 +262,15 @@ bool SaveStringTextToFile( return true; } +bool UCookAssetsCommandlet::SavePackage(const FString &PackagePath, UPackage *Package) const +{ + FString PackageFileName = FPackageName::LongPackageNameToFilename(PackagePath, + FPackageName::GetMapPackageExtension()); + + return UPackage::SavePackage(Package, World, EObjectFlags::RF_Public | EObjectFlags::RF_Standalone, + *PackageFileName, GError, nullptr, true, true, SAVE_NoError); +} + int32 UCookAssetsCommandlet::Main(const FString &Params) { FPackageParams PackageParams = ParseParams(Params); @@ -305,5 +322,4 @@ int32 UCookAssetsCommandlet::Main(const FString &Params) return 0; } - #endif diff --git a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Commandlet/CookAssetsCommandlet.h b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Commandlet/CookAssetsCommandlet.h index edc7f1af3..f34afbd31 100644 --- a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Commandlet/CookAssetsCommandlet.h +++ b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Commandlet/CookAssetsCommandlet.h @@ -148,4 +148,9 @@ private: */ UMaterial *TerrainNodeMaterial; + /** + * Saves the package + */ + bool SavePackage(const FString &PackagePath, UPackage *Package) const; + };