diff --git a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Game/CarlaGameModeBase.cpp b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Game/CarlaGameModeBase.cpp index 77e6ec9a5..53a72f141 100644 --- a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Game/CarlaGameModeBase.cpp +++ b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Game/CarlaGameModeBase.cpp @@ -127,7 +127,7 @@ void ACarlaGameModeBase::BeginPlay() Super::BeginPlay(); LoadMapLayer(GameInstance->GetCurrentMapLayer()); - + ReadyToRegisterObjects = true; if (true) { /// @todo If semantic segmentation enabled. check(GetWorld() != nullptr); @@ -163,8 +163,7 @@ void ACarlaGameModeBase::BeginPlay() Recorder->GetReplayer()->CheckPlayAfterMapLoaded(); } - RegisterEnvironmentObject(); - + RegisterEnvironmentObjects(); } void ACarlaGameModeBase::Tick(float DeltaSeconds) @@ -361,7 +360,7 @@ TArray ACarlaGameModeBase::GetAllBBsOfLevel(uint8 TagQueried) return BoundingBoxes; } -void ACarlaGameModeBase::RegisterEnvironmentObject() +void ACarlaGameModeBase::RegisterEnvironmentObjects() { // Get all actors of the level TArray FoundActors; @@ -392,8 +391,11 @@ void ACarlaGameModeBase::LoadMapLayer(int32 MapLayers) } // Register new actors and tag them - RegisterEnvironmentObject(); - ATagger::TagActorsInLevel(*GetWorld(), true); + if(ReadyToRegisterObjects) + { + RegisterEnvironmentObjects(); + ATagger::TagActorsInLevel(*GetWorld(), true); + } } @@ -413,7 +415,10 @@ void ACarlaGameModeBase::UnLoadMapLayer(int32 MapLayers) } // Update stored registered objects (discarding the deleted objects) - RegisterEnvironmentObject(); + if(ReadyToRegisterObjects) + { + RegisterEnvironmentObjects(); + } } void ACarlaGameModeBase::ConvertMapLayerMaskToMapNames(int32 MapLayer, TArray& OutLevelNames) diff --git a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Game/CarlaGameModeBase.h b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Game/CarlaGameModeBase.h index b8c469094..05c6f1c1b 100644 --- a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Game/CarlaGameModeBase.h +++ b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Game/CarlaGameModeBase.h @@ -91,7 +91,7 @@ private: void ParseOpenDrive(const FString &MapName); - void RegisterEnvironmentObject(); + void RegisterEnvironmentObjects(); void ConvertMapLayerMaskToMapNames(int32 MapLayer, TArray& OutLevelNames); @@ -130,4 +130,6 @@ private: boost::optional Map; + bool ReadyToRegisterObjects = false; + };