diff --git a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Vegetation/VegetationManager.cpp b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Vegetation/VegetationManager.cpp index bf53db38e..1ec2d264d 100644 --- a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Vegetation/VegetationManager.cpp +++ b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Vegetation/VegetationManager.cpp @@ -197,6 +197,7 @@ void AVegetationManager::BeginPlay() LargeMap = UCarlaStatics::GetLargeMapManager(GetWorld()); FWorldDelegates::LevelAddedToWorld.AddUObject(this, &AVegetationManager::OnLevelAddedToWorld); FWorldDelegates::LevelRemovedFromWorld.AddUObject(this, &AVegetationManager::OnLevelRemovedFromWorld); + GetWorldTimerManager().SetTimer(UpdatePoolInactiveTransformTimer, this, &AVegetationManager::UpdatePoolBasePosition, 30.0f, true, 15.0f); } void AVegetationManager::Tick(float DeltaTime) @@ -610,6 +611,27 @@ AActor* AVegetationManager::CreateFoliage(const FFoliageBlueprint& BP, const FTr return Actor; } +void AVegetationManager::UpdatePoolBasePosition() +{ + TRACE_CPUPROFILER_EVENT_SCOPE(AVegetationManager::UpdatePoolBasePosition); + if (!IsValid(HeroVehicle)) + return; + UE_LOG(LogCarla, Display, TEXT("UpdatePoolBasePosition")); + const FTransform HeroTransform = LargeMap->LocalToGlobalTransform(HeroVehicle->GetActorTransform()); + const FVector HeroLocation = HeroTransform.GetLocation(); + const FTransform PoolTransform(HeroTransform.GetRotation(), FVector(HeroLocation.X, HeroLocation.Y, -1000.0f), FVector(1.0f, 1.0f, 1.0f)); + for (TPair>& Element : ActorPool) + { + TArray& Pool = Element.Value; + for (FPooledActor& PooledActor : Pool) + { + if (PooledActor.InUse) + continue; + PooledActor.Actor->SetActorTransform(PoolTransform, true, nullptr, ETeleportType::ResetPhysics); + } + } +} + /********************************************************************************/ /********** TILES ***************************************************************/ /********************************************************************************/ diff --git a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Vegetation/VegetationManager.h b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Vegetation/VegetationManager.h index 75fbdb868..8fe0ea626 100644 --- a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Vegetation/VegetationManager.h +++ b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Vegetation/VegetationManager.h @@ -85,6 +85,9 @@ public: void AddVehicle(ACarlaWheeledVehicle* Vehicle); void RemoveVehicle(ACarlaWheeledVehicle* Vehicle); + UFUNCTION(BlueprintCallable) + void UpdatePoolBasePosition(); + public: UPROPERTY(Category = "CARLA Vegetation Spwaner", EditDefaultsOnly) bool DebugMaterials {false}; @@ -157,4 +160,6 @@ private: TMap TileCache {}; //Pools TMap> ActorPool {}; + + FTimerHandle UpdatePoolInactiveTransformTimer; };