diff --git a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Sensor/SensorFactory.cpp b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Sensor/SensorFactory.cpp index 7a853d8ea..1f9f0c5ff 100644 --- a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Sensor/SensorFactory.cpp +++ b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Sensor/SensorFactory.cpp @@ -27,14 +27,17 @@ FActorSpawnResult ASensorFactory::SpawnActor( const FActorDescription &Description) { FActorSpawnParameters Params; - static int32 COUNTER = 0u; - Params.Name = FName(*(Description.Id + FString::FromInt(++COUNTER))); auto *World = GetWorld(); if (World == nullptr) { return {}; } - auto *Sensor = World->SpawnActor(Description.Class, Transform, Params); + auto *Sensor = World->SpawnActorDeferred( + Description.Class, + Transform, + this, + nullptr, + ESpawnActorCollisionHandlingMethod::AlwaysSpawn); if (Sensor != nullptr) { using ABFL = UActorBlueprintFunctionLibrary; @@ -47,5 +50,6 @@ FActorSpawnResult ASensorFactory::SpawnActor( PostProcessEffect::FromString( ABFL::RetrieveActorAttributeToString("post_processing", Description.Variations, "SceneFinal"))); } + UGameplayStatics::FinishSpawningActor(Sensor, Transform); return FActorSpawnResult{Sensor}; }