diff --git a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/MapGen/LargeMapManager.cpp b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/MapGen/LargeMapManager.cpp index bef665a9f..227bbd441 100644 --- a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/MapGen/LargeMapManager.cpp +++ b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/MapGen/LargeMapManager.cpp @@ -209,6 +209,17 @@ void ALargeMapManager::OnActorSpawned( } +ACarlaWheeledVehicle* ALargeMapManager::GetHeroVehicle() +{ + if (ActorsToConsider.Num() > 0) + { + ACarlaWheeledVehicle* Hero = Cast(ActorsToConsider[0]); + if (IsValid(Hero)) + return Hero; + } + return nullptr; +} + void ALargeMapManager::OnActorDestroyed(AActor* DestroyedActor) { LM_LOG(Warning, "ALargeMapManager::OnActorDestroyed %s", *DestroyedActor->GetName()); diff --git a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/MapGen/LargeMapManager.h b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/MapGen/LargeMapManager.h index 0197e80c6..f5f8ff8f6 100644 --- a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/MapGen/LargeMapManager.h +++ b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/MapGen/LargeMapManager.h @@ -197,6 +197,8 @@ public: FCarlaMapTile& LoadCarlaMapTile(FString TileMapPath, TileID TileId); + ACarlaWheeledVehicle* GetHeroVehicle(); + protected: void UpdateTilesState(); diff --git a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Vegetation/SpringBasedVegetationComponent.cpp b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Vegetation/SpringBasedVegetationComponent.cpp index 478aea9e2..15fe87a8c 100644 --- a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Vegetation/SpringBasedVegetationComponent.cpp +++ b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Vegetation/SpringBasedVegetationComponent.cpp @@ -301,7 +301,7 @@ void USpringBasedVegetationComponent::GenerateSkeletonHierarchy() } } - UpdateGlobalTransform(); + // UpdateGlobalTransform(); } void USpringBasedVegetationComponent::BeginPlay() @@ -330,47 +330,6 @@ void USpringBasedVegetationComponent::BeginPlay() GenerateSkeletonHierarchy(); } - // Get resting pose for bones - auto *AnimInst = SkeletalMesh->GetAnimInstance(); - if (!AnimInst) - { - OTHER_LOG(Error, "Could not get animation instance."); - return; - } - UWalkerAnim *WalkerAnim = Cast(AnimInst); - if (!WalkerAnim) - { - OTHER_LOG(Error, "Could not get UWalkerAnim."); - return; - } - - // get current pose - FPoseSnapshot TempSnapshot; - SkeletalMesh->SnapshotPose(TempSnapshot); - - // copy pose - WalkerAnim->Snap = TempSnapshot; - - for (int i=0; iGetSocketTransform(FName(*Joint.JointName), ERelativeTransformSpace::RTS_ParentBoneSpace); - Joint.Transform = JointTransform; - Joint.RestingAngles = JointTransform.Rotator(); - OTHER_LOG(Log, "Getting info for bone %s, %f, %f, %f, %f", *Joint.JointName, Joint.RestingAngles.Pitch, Joint.RestingAngles.Yaw, Joint.RestingAngles.Roll); - if(i > 0) - { - FSkeletonJoint& ParentJoint = Skeleton.Joints[Joint.ParentId]; - FVector BoneCOM = Joint.Transform.GetLocation()*0.5f; - float BoneLength = Joint.Transform.GetLocation().Size(); - ParentJoint.Bones.Add({10, BoneLength, BoneCOM}); - } - } - for (int i=0; iIndicesInUse.Emplace(Index); + + Actor->SetActorHiddenInGame(false); Actor->SetActorEnableCollision(true); Actor->SetActorTickEnabled(true); @@ -65,8 +71,17 @@ void FPooledActor::EnableActor() void FPooledActor::DisableActor() { TRACE_CPUPROFILER_EVENT_SCOPE(FPooledActor::DisableActor); + + if (TileMeshComponent) + { + if (TileMeshComponent->IndicesInUse.Num() > 0) + TileMeshComponent->IndicesInUse.RemoveSingle(Index); + } + InUse = false; - Actor->SetActorTransform(FTransform()); + Index = -1; + TileMeshComponent = nullptr; + Actor->SetActorHiddenInGame(true); Actor->SetActorEnableCollision(false); Actor->SetActorTickEnabled(false); @@ -189,20 +204,32 @@ void AVegetationManager::Tick(float DeltaTime) } if (!LargeMap) return; - bool FoundVehicles = CheckIfAnyVehicleInLevel(); - if (!FoundVehicles) - return; - - UpdateVehiclesDetectionBoxes(); - + if (!IsValid(HeroVehicle)) + { + HeroVehicle = LargeMap->GetHeroVehicle(); + if (!IsValid(HeroVehicle)) + return; + } + + HeroVehicle->UpdateDetectionBox(); TArray TilesInUse = GetTilesInUse(); if (TilesInUse.Num() == 0) + { + UE_LOG(LogCarla, Warning, TEXT("No tiles detected.")); return; + } + + for (const FString& TileName : TilesInUse) + { + FTileData* Tile = TileCache.Find(TileName); + if (!Tile) + continue; + UpdateMaterials(Tile); + TArray ElementsToSpawn = GetElementsToSpawn(Tile); + SpawnSkeletalFoliages(ElementsToSpawn); + DestroySkeletalFoliages(); + } - UpdateMaterials(TilesInUse); - TArray>> ElementsToSpawn = GetElementsToSpawn(TilesInUse); - SpawnSkeletalFoliages(ElementsToSpawn); - DestroySkeletalFoliages(); } /********************************************************************************/ @@ -213,9 +240,7 @@ void AVegetationManager::AddVehicle(ACarlaWheeledVehicle* Vehicle) TRACE_CPUPROFILER_EVENT_SCOPE(AVegetationManager::AddVehicle); if (!IsValid(Vehicle)) return; - if (VehiclesInLevel.Contains(Vehicle)) - return; - VehiclesInLevel.Emplace(Vehicle); + HeroVehicle = Vehicle; UE_LOG(LogCarla, Display, TEXT("Vehicle added.")); } @@ -224,9 +249,7 @@ void AVegetationManager::RemoveVehicle(ACarlaWheeledVehicle* Vehicle) TRACE_CPUPROFILER_EVENT_SCOPE(AVegetationManager::RemoveVehicle); if (!IsValid(Vehicle)) return; - if (!VehiclesInLevel.Contains(Vehicle)) - return; - VehiclesInLevel.RemoveSingle(Vehicle); + HeroVehicle = nullptr; UE_LOG(LogCarla, Display, TEXT("Vehicle removed.")); } @@ -245,6 +268,8 @@ void AVegetationManager::CreateOrUpdateTileCache(ULevel* InLevel) TileData.InstancedFoliageActor = InstancedFoliageActor; break; } + if (!IsValid(TileData.InstancedFoliageActor)) + return; for (AActor* Actor : InLevel->Actors) { @@ -254,18 +279,17 @@ void AVegetationManager::CreateOrUpdateTileCache(ULevel* InLevel) TileData.ProceduralFoliageVolume = ProceduralFoliageVolume; break; } + if (!IsValid(TileData.ProceduralFoliageVolume)) + return; + const FString TileName = TileData.InstancedFoliageActor->GetLevel()->GetOuter()->GetName(); FTileData* ExistingTileData = TileCache.Find(TileName); if (ExistingTileData) { ExistingTileData->InstancedFoliageActor = TileData.InstancedFoliageActor; ExistingTileData->ProceduralFoliageVolume = TileData.ProceduralFoliageVolume; - for (FTileMeshComponent& Element : ExistingTileData->TileMeshesCache) - { - Element.InstancedStaticMeshComponent = nullptr; - Element.IndicesInUse.Empty(); - } ExistingTileData->TileMeshesCache.Empty(); + ExistingTileData->MaterialInstanceDynamicCache.Empty(); SetTileDataInternals(*ExistingTileData); } else @@ -273,7 +297,6 @@ void AVegetationManager::CreateOrUpdateTileCache(ULevel* InLevel) SetTileDataInternals(TileData); TileCache.Emplace(TileName, TileData); } - } void AVegetationManager::SetTileDataInternals(FTileData& TileData) @@ -316,7 +339,8 @@ void AVegetationManager::SetMaterialCache(FTileData& TileData) if (TileData.MaterialInstanceDynamicCache.Num() > 0) TileData.MaterialInstanceDynamicCache.Empty(); - const float Distance = VehiclesInLevel.Last()->DetectionSize * 2.0f; + #define MATERIAL_HIDE_DISTANCE 500.0f + const float Distance = MATERIAL_HIDE_DISTANCE; for (FTileMeshComponent& Element : TileData.TileMeshesCache) { UInstancedStaticMeshComponent* Mesh = Element.InstancedStaticMeshComponent; @@ -368,7 +392,7 @@ void AVegetationManager::UpdateFoliageBlueprintCache(ULevel* InLevel) if (!NewFoliageBlueprint.IsValid()) { - UE_LOG(LogCarla, Error, TEXT("Blueprint %s was invalid."), *NewFoliageBlueprint.BPFullClassName); + UE_LOG(LogCarla, Warning, TEXT("Blueprint %s was invalid."), *NewFoliageBlueprint.BPFullClassName); } else { @@ -384,7 +408,7 @@ void AVegetationManager::FreeTileCache(ULevel* InLevel) { if (!IsValid(InLevel)) return; - FTileData TileData {}; + AInstancedFoliageActor* TileInstancedFoliageActor = nullptr; for (AActor* Actor : InLevel->Actors) { if (!IsValid(Actor)) @@ -392,12 +416,12 @@ void AVegetationManager::FreeTileCache(ULevel* InLevel) AInstancedFoliageActor* InstancedFoliageActor = Cast(Actor); if (!IsValid(InstancedFoliageActor)) continue; - TileData.InstancedFoliageActor = InstancedFoliageActor; + TileInstancedFoliageActor = InstancedFoliageActor; break; } - if (TileData.InstancedFoliageActor == nullptr) + if (!IsValid(TileInstancedFoliageActor)) return; - const FString TileName = TileData.InstancedFoliageActor->GetLevel()->GetOuter()->GetName(); + const FString TileName = TileInstancedFoliageActor->GetLevel()->GetOuter()->GetName(); FTileData* ExistingTileData = TileCache.Find(TileName); if (ExistingTileData) { @@ -407,6 +431,9 @@ void AVegetationManager::FreeTileCache(ULevel* InLevel) Element.IndicesInUse.Empty(); } ExistingTileData->TileMeshesCache.Empty(); + ExistingTileData->InstancedFoliageActor = nullptr; + ExistingTileData->ProceduralFoliageVolume = nullptr; + TileCache.Remove(TileName); } } @@ -414,100 +441,83 @@ void AVegetationManager::FreeTileCache(ULevel* InLevel) /********************************************************************************/ /********** TICK ****************************************************************/ /********************************************************************************/ -void AVegetationManager::UpdateVehiclesDetectionBoxes() -{ - TRACE_CPUPROFILER_EVENT_SCOPE(AVegetationManager::UpdateVehiclesDetectionBoxes); - for (ACarlaWheeledVehicle* Vehicle : VehiclesInLevel) - Vehicle->UpdateDetectionBox(); -} - -void AVegetationManager::UpdateMaterials(TArray& Tiles) +void AVegetationManager::UpdateMaterials(FTileData* Tile) { TRACE_CPUPROFILER_EVENT_SCOPE(AVegetationManager::UpdateMaterials); - const FLinearColor Position = VehiclesInLevel.Last()->GetActorLocation(); - for (const FString& TileName : Tiles) - { - FTileData* TileData = TileCache.Find(TileName); - if (!TileData) - continue; - TileData->UpdateMaterialCache(Position, DebugMaterials); - } + const FTransform GlobalTransform = LargeMap->LocalToGlobalTransform(HeroVehicle->GetActorTransform()); + const FLinearColor Position = GlobalTransform.GetLocation(); + Tile->UpdateMaterialCache(Position, DebugMaterials); } -TArray>> AVegetationManager::GetElementsToSpawn(const TArray& Tiles) +TArray AVegetationManager::GetElementsToSpawn(FTileData* Tile) { TRACE_CPUPROFILER_EVENT_SCOPE(AVegetationManager::GetElementsToSpawn); - TArray>> Results; - for (const FString& TileKey : Tiles) + TArray Results; + int32 i = -1; + for (FTileMeshComponent& Element : Tile->TileMeshesCache) { - FTileData* Tile = TileCache.Find(TileKey); - if (!Tile) + TRACE_CPUPROFILER_EVENT_SCOPE(Update Foliage Usage); + ++i; + UInstancedStaticMeshComponent* InstancedStaticMeshComponent = Element.InstancedStaticMeshComponent; + const FString Path = InstancedStaticMeshComponent->GetStaticMesh()->GetPathName(); + FFoliageBlueprint* BP = FoliageBlueprintCache.Find(Path); + if (!BP) + continue; + TArray Indices = HeroVehicle->GetFoliageInstancesCloseToVehicle(InstancedStaticMeshComponent); + if (Indices.Num() == 0) continue; - for (FTileMeshComponent& Element : Tile->TileMeshesCache) - { - TRACE_CPUPROFILER_EVENT_SCOPE(Update Foliage Usage); - UInstancedStaticMeshComponent* InstancedStaticMeshComponent = Element.InstancedStaticMeshComponent; - const FString Path = InstancedStaticMeshComponent->GetStaticMesh()->GetPathName(); - FFoliageBlueprint* BP = FoliageBlueprintCache.Find(Path); - if (!BP) - continue; - TArray Indices = VehiclesInLevel.Last()->GetFoliageInstancesCloseToVehicle(InstancedStaticMeshComponent); - if (Indices.Num() == 0) - continue; - TArray NewIndices; - for (int32 Index : Indices) - { - if (Element.IndicesInUse.Contains(Index)) - continue; - NewIndices.Emplace(Index); - } - Element.IndicesInUse = Indices; - TPair> NewElement {}; - NewElement.Key = *BP; - TArray Transforms; - for (int32 Index : NewIndices) - { - FTransform Transform; - InstancedStaticMeshComponent->GetInstanceTransform(Index, Transform, true); - FTransform GlobalTransform = LargeMap->LocalToGlobalTransform(Transform); - Transforms.Emplace(GlobalTransform); - } - if (Transforms.Num() > 0) - { - NewElement.Value = Transforms; - Results.Emplace(NewElement); - } + TArray NewIndices; + for (int32 Index : Indices) + { + if (Element.IndicesInUse.Contains(Index)) + continue; + NewIndices.Emplace(Index); } + + FElementsToSpawn NewElement {}; + NewElement.TileMeshComponent = &Tile->TileMeshesCache[i]; + NewElement.BP = *BP; + for (int32 Index : NewIndices) + { + FTransform Transform; + InstancedStaticMeshComponent->GetInstanceTransform(Index, Transform, true); + FTransform GlobalTransform = LargeMap->LocalToGlobalTransform(Transform); + NewElement.TransformIndex.Emplace(TPair(GlobalTransform, Index)); + } + if (NewElement.TransformIndex.Num() > 0) + Results.Emplace(NewElement); } return Results; } -void AVegetationManager::SpawnSkeletalFoliages(TArray>>& ElementsToSpawn) +void AVegetationManager::SpawnSkeletalFoliages(TArray& ElementsToSpawn) { TRACE_CPUPROFILER_EVENT_SCOPE(AVegetationManager::SpawnSkeletalFoliages); - for (TPair>& Element : ElementsToSpawn) + for (FElementsToSpawn& Element : ElementsToSpawn) { - FFoliageBlueprint BP = Element.Key; - TArray* Pool = ActorPool.Find(BP.BPFullClassName); - for (const FTransform& Transform : Element.Value) + TArray* Pool = ActorPool.Find(Element.BP.BPFullClassName); + if (Pool == nullptr) + continue; + for (const TPair& TransformIndex : Element.TransformIndex) { - bool Ok = EnableActorFromPool(Transform, *Pool); + const FTransform& Transform = TransformIndex.Key; + int32 Index = TransformIndex.Value; + if (Element.TileMeshComponent->IndicesInUse.Contains(Index)) + continue; + bool Ok = EnableActorFromPool(Transform, Index, Element.TileMeshComponent, *Pool); if (Ok) { - UE_LOG(LogCarla, Display, TEXT("Pooled actor: %s"), *BP.BPFullClassName); + } else { FPooledActor NewElement; - NewElement.GlobalTransform = Transform; - FTransform LocalTransform = LargeMap->GlobalToLocalTransform(Transform); - NewElement.Actor = CreateFoliage(BP, LocalTransform); + NewElement.Actor = CreateFoliage(Element.BP, {}); if (IsValid(NewElement.Actor)) { - NewElement.EnableActor(); + NewElement.EnableActor(Transform, Index, Element.TileMeshComponent); Pool->Emplace(NewElement); - UE_LOG(LogCarla, Display, TEXT("Created actor: %s"), *BP.BPFullClassName); } } } @@ -525,31 +535,27 @@ void AVegetationManager::DestroySkeletalFoliages() if (!Actor.InUse) continue; const FVector Location = Actor.GlobalTransform.GetLocation(); - if (!VehiclesInLevel.Last()->IsInVehicleRange(Location)) + if (!HeroVehicle->IsInVehicleRange(Location)) { Actor.DisableActor(); - UE_LOG(LogCarla, Display, TEXT("Disabled Actor")); } } } } -bool AVegetationManager::EnableActorFromPool(const FTransform& Transform, TArray& Pool) +bool AVegetationManager::EnableActorFromPool(const FTransform& Transform, int32 Index, FTileMeshComponent* TileMeshComponent, TArray& Pool) { TRACE_CPUPROFILER_EVENT_SCOPE(AVegetationManager::EnableActorFromPool); for (FPooledActor& PooledActor : Pool) { if (PooledActor.InUse) continue; - PooledActor.GlobalTransform = Transform; - FTransform LocalTransform = Transform; - LocalTransform = LargeMap->GlobalToLocalTransform(Transform); - PooledActor.EnableActor(); - PooledActor.Actor->SetActorLocationAndRotation(LocalTransform.GetLocation(), LocalTransform.Rotator(), true, nullptr, ETeleportType::ResetPhysics); + PooledActor.EnableActor(Transform, Index, TileMeshComponent); + PooledActor.Actor->SetActorLocationAndRotation(Transform.GetLocation(), Transform.Rotator(), true, nullptr, ETeleportType::ResetPhysics); if (SpawnScale <= 1.01f && SpawnScale >= 0.99f) - PooledActor.Actor->SetActorScale3D(LocalTransform.GetScale3D()); + PooledActor.Actor->SetActorScale3D(Transform.GetScale3D()); else - PooledActor.Actor->SetActorScale3D({SpawnScale, SpawnScale, SpawnScale}); + PooledActor.Actor->SetActorScale3D({SpawnScale, SpawnScale, SpawnScale}); return true; } return false; @@ -611,12 +617,6 @@ void AVegetationManager::OnLevelRemovedFromWorld(ULevel* InLevel, UWorld* InWorl FreeTileCache(InLevel); } -bool AVegetationManager::CheckIfAnyVehicleInLevel() const -{ - TRACE_CPUPROFILER_EVENT_SCOPE(AVegetationManager::CheckIfAnyVehicleInLevel); - return VehiclesInLevel.Num() > 0; -} - bool AVegetationManager::IsFoliageTypeEnabled(const FString& Path) const { TRACE_CPUPROFILER_EVENT_SCOPE(AVegetationManager::IsFoliageTypeEnabled); @@ -675,18 +675,12 @@ TArray AVegetationManager::GetTilesInUse() continue; const FBox Box = Procedural->ProceduralComponent->GetBounds(); if (!Box.IsValid) - continue; - - for (ACarlaWheeledVehicle* Vehicle : VehiclesInLevel) - { - if (!IsValid(Vehicle)) - continue; - if (Box.IsInside(Vehicle->GetActorLocation())) + continue; + if (Box.IsInside(HeroVehicle->GetActorLocation())) { Results.Emplace(Element.Key); break; } - } } return Results; } diff --git a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Vegetation/VegetationManager.h b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Vegetation/VegetationManager.h index d08d37c44..38107a576 100644 --- a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Vegetation/VegetationManager.h +++ b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Vegetation/VegetationManager.h @@ -60,11 +60,22 @@ struct FPooledActor bool InUse { false }; AActor* Actor { nullptr }; FTransform GlobalTransform {FTransform()}; + int32 Index {-1}; + FTileMeshComponent* TileMeshComponent {nullptr}; - void EnableActor(); + void EnableActor(const FTransform& Transform, int32 NewIndex, FTileMeshComponent* NewTileMeshComponent); void DisableActor(); }; +USTRUCT() +struct FElementsToSpawn +{ + GENERATED_BODY() + FTileMeshComponent* TileMeshComponent; + FFoliageBlueprint BP; + TArray> TransformIndex; +}; + UCLASS() class CARLA_API AVegetationManager : public AActor { @@ -107,17 +118,15 @@ protected: private: bool IsFoliageTypeEnabled(const FString& Path) const; - bool CheckIfAnyVehicleInLevel() const; bool CheckForNewTiles() const; TArray GetTilesInUse(); - void UpdateVehiclesDetectionBoxes(); - void UpdateMaterials(TArray& Tiles); - TArray>> GetElementsToSpawn(const TArray& Tiles); - void SpawnSkeletalFoliages(TArray>>& ElementsToSpawn); + void UpdateMaterials(FTileData* Tile); + TArray GetElementsToSpawn(FTileData* Tile); + void SpawnSkeletalFoliages(TArray& ElementsToSpawn); void DestroySkeletalFoliages(); - bool EnableActorFromPool(const FTransform& Transform, TArray& Pool); + bool EnableActorFromPool(const FTransform& Transform, int32 Index, FTileMeshComponent* TileMeshComponent, TArray& Pool); void CreateOrUpdateTileCache(ULevel* InLevel); void UpdateFoliageBlueprintCache(ULevel* InLevel); @@ -138,7 +147,7 @@ private: private: //Actors ALargeMapManager* LargeMap {nullptr}; - TArray VehiclesInLevel {}; + ACarlaWheeledVehicle* HeroVehicle {nullptr}; //Caches TMap FoliageBlueprintCache {}; TMap TileCache {}; diff --git a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Vehicle/CarlaWheeledVehicle.cpp b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Vehicle/CarlaWheeledVehicle.cpp index a7bab3368..ec5e5b513 100644 --- a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Vehicle/CarlaWheeledVehicle.cpp +++ b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Vehicle/CarlaWheeledVehicle.cpp @@ -205,26 +205,19 @@ void ACarlaWheeledVehicle::BeginPlay() bool ACarlaWheeledVehicle::IsInVehicleRange(const FVector& Location) const { TRACE_CPUPROFILER_EVENT_SCOPE(ACarlaWheeledVehicle::IsInVehicleRange); - - float Distance = 0.0f; - ALargeMapManager* LargeMap = UCarlaStatics::GetLargeMapManager(GetWorld()); - if (LargeMap) - { - FTransform GlobalTransform = LargeMap->LocalToGlobalTransform(GetActorTransform()); - Distance = FVector::Distance(Location, GlobalTransform.GetLocation()); - } - else - { - Distance = FVector::Distance(Location, GetActorTransform().GetLocation()); - } - return Distance < DetectionSize * 10.0f; + + return FoliageBoundingBox.IsInside(Location); } void ACarlaWheeledVehicle::UpdateDetectionBox() { + ALargeMapManager* LargeMap = UCarlaStatics::GetLargeMapManager(GetWorld()); + if (!IsValid(LargeMap)) + return; + FTransform GlobalTransform = LargeMap->LocalToGlobalTransform(GetActorTransform()); const FVector Vec { DetectionSize, DetectionSize, DetectionSize}; FBox Box = FBox(-Vec, Vec); - FoliageBoundingBox = Box.TransformBy(GetActorTransform()); + FoliageBoundingBox = Box.TransformBy(GlobalTransform); } const TArray ACarlaWheeledVehicle::GetFoliageInstancesCloseToVehicle(const UInstancedStaticMeshComponent* Component) const @@ -937,8 +930,8 @@ FVector ACarlaWheeledVehicle::GetVelocity() const void ACarlaWheeledVehicle::EndPlay(const EEndPlayReason::Type EndPlayReason) { ShowDebugTelemetry(false); - RemoveReferenceToManager(); Super::EndPlay(EndPlayReason); + RemoveReferenceToManager(); } void ACarlaWheeledVehicle::OpenDoor(const EVehicleDoor DoorIdx) { diff --git a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Vehicle/CarlaWheeledVehicle.h b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Vehicle/CarlaWheeledVehicle.h index 7cd7d0a6c..f69e52902 100644 --- a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Vehicle/CarlaWheeledVehicle.h +++ b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Vehicle/CarlaWheeledVehicle.h @@ -354,7 +354,7 @@ private: public: UPROPERTY(Category = "CARLA Wheeled Vehicle", EditDefaultsOnly) - float DetectionSize { 200.0f }; + float DetectionSize { 500.0f }; UPROPERTY(Category = "CARLA Wheeled Vehicle", VisibleAnywhere, BlueprintReadOnly) FBox FoliageBoundingBox;