diff --git a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Game/CarlaGameModeBase.cpp b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Game/CarlaGameModeBase.cpp index ec97fee3c..878107d7f 100644 --- a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Game/CarlaGameModeBase.cpp +++ b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Game/CarlaGameModeBase.cpp @@ -441,6 +441,7 @@ void ACarlaGameModeBase::EnableEnvironmentObjects( void ACarlaGameModeBase::LoadMapLayer(int32 MapLayers) { const UWorld* World = GetWorld(); + UGameplayStatics::FlushLevelStreaming(World); TArray LevelsToLoad; ConvertMapLayerMaskToMapNames(MapLayers, LevelsToLoad); @@ -449,16 +450,17 @@ void ACarlaGameModeBase::LoadMapLayer(int32 MapLayers) LatentInfo.CallbackTarget = this; LatentInfo.ExecutionFunction = "OnLoadStreamLevel"; LatentInfo.Linkage = 0; - LatentInfo.UUID = 1; + LatentInfo.UUID = LatentInfoUUID; PendingLevelsToLoad = LevelsToLoad.Num(); for(FName& LevelName : LevelsToLoad) { + LatentInfoUUID++; UGameplayStatics::LoadStreamLevel(World, LevelName, true, true, LatentInfo); - LatentInfo.UUID++; + LatentInfo.UUID = LatentInfoUUID; + UGameplayStatics::FlushLevelStreaming(World); } - } void ACarlaGameModeBase::UnLoadMapLayer(int32 MapLayers) @@ -471,15 +473,17 @@ void ACarlaGameModeBase::UnLoadMapLayer(int32 MapLayers) FLatentActionInfo LatentInfo; LatentInfo.CallbackTarget = this; LatentInfo.ExecutionFunction = "OnUnloadStreamLevel"; - LatentInfo.UUID = 1; + LatentInfo.UUID = LatentInfoUUID; LatentInfo.Linkage = 0; PendingLevelsToUnLoad = LevelsToUnLoad.Num(); for(FName& LevelName : LevelsToUnLoad) { + LatentInfoUUID++; UGameplayStatics::UnloadStreamLevel(World, LevelName, LatentInfo, false); - LatentInfo.UUID++; + LatentInfo.UUID = LatentInfoUUID; + UGameplayStatics::FlushLevelStreaming(World); } } diff --git a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Game/CarlaGameModeBase.h b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Game/CarlaGameModeBase.h index b1f41b5d4..a6829beaf 100644 --- a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Game/CarlaGameModeBase.h +++ b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Game/CarlaGameModeBase.h @@ -164,4 +164,8 @@ private: bool ReadyToRegisterObjects = false; + // We keep a global uuid to allow the load/unload layer methods to be called + // in the same tick + int32 LatentInfoUUID = 0; + };