moved bIsAlive to false out of the destructor
This commit is contained in:
parent
4e37b263c7
commit
0ac47c8950
|
@ -45,11 +45,6 @@ static FString GetVersionFromFString(const FString& String)
|
|||
|
||||
FTileData::~FTileData()
|
||||
{
|
||||
for(std::shared_ptr<FTileMeshComponent>&
|
||||
TileMeshComponent : TileMeshesCache)
|
||||
{
|
||||
TileMeshComponent->bIsAlive = false;
|
||||
}
|
||||
}
|
||||
|
||||
/********************************************************************************/
|
||||
|
@ -101,9 +96,12 @@ void FPooledActor::DisableActor()
|
|||
|
||||
if (TileMeshComponent)
|
||||
{
|
||||
if (TileMeshComponent->IndicesInUse.Contains(Index))
|
||||
if (TileMeshComponent->bIsAlive)
|
||||
{
|
||||
TileMeshComponent->IndicesInUse.RemoveSingle(Index);
|
||||
if (TileMeshComponent->IndicesInUse.Contains(Index))
|
||||
{
|
||||
TileMeshComponent->IndicesInUse.RemoveSingle(Index);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -190,6 +188,7 @@ void FTileData::UpdateTileMeshComponent(UInstancedStaticMeshComponent* NewInstan
|
|||
{
|
||||
int32 CurrentCount = Element.InstancedStaticMeshComponent->GetInstanceCount();
|
||||
int32 NewCount = NewInstancedStaticMeshComponent->GetInstanceCount();
|
||||
Element.bIsAlive = true;
|
||||
if (NewCount > CurrentCount)
|
||||
{
|
||||
Element.InstancedStaticMeshComponent = NewInstancedStaticMeshComponent;
|
||||
|
@ -473,6 +472,7 @@ void AVegetationManager::FreeTileCache(ULevel* InLevel)
|
|||
: ExistingTileData->TileMeshesCache)
|
||||
{
|
||||
Element->IndicesInUse.Empty();
|
||||
Element->bIsAlive = false;
|
||||
}
|
||||
ExistingTileData->TileMeshesCache.Empty();
|
||||
ExistingTileData->InstancedFoliageActor = nullptr;
|
||||
|
@ -495,8 +495,6 @@ void AVegetationManager::UpdateMaterials(FTileData* Tile)
|
|||
|
||||
TArray<FElementsToSpawn> AVegetationManager::GetElementsToSpawn(FTileData* Tile)
|
||||
{
|
||||
UE_LOG(LogCarla, Error, TEXT("GetElementsToSpawn"));
|
||||
|
||||
TRACE_CPUPROFILER_EVENT_SCOPE(AVegetationManager::GetElementsToSpawn);
|
||||
TArray<FElementsToSpawn> Results;
|
||||
int32 i = -1;
|
||||
|
@ -515,13 +513,11 @@ TArray<FElementsToSpawn> AVegetationManager::GetElementsToSpawn(FTileData* Tile)
|
|||
TArray<int32> Indices = HeroVehicle->GetFoliageInstancesCloseToVehicle(InstancedStaticMeshComponent);
|
||||
if (Indices.Num() == 0)
|
||||
continue;
|
||||
UE_LOG(LogCarla, Error, TEXT("%d instances of %s close to vehicle"), Indices.Num(), *BP->BPFullClassName);
|
||||
TArray<int32> NewIndices;
|
||||
for (int32 Index : Indices)
|
||||
{
|
||||
if (Element.IndicesInUse.Contains(Index))
|
||||
{
|
||||
UE_LOG(LogCarla, Error, TEXT("Index %d already in use"), Index);
|
||||
continue;
|
||||
}
|
||||
NewIndices.Emplace(Index);
|
||||
|
@ -544,7 +540,6 @@ TArray<FElementsToSpawn> AVegetationManager::GetElementsToSpawn(FTileData* Tile)
|
|||
|
||||
void AVegetationManager::SpawnSkeletalFoliages(TArray<FElementsToSpawn>& ElementsToSpawn)
|
||||
{
|
||||
UE_LOG(LogCarla, Error, TEXT("SpawnSkeletalFoliages"));
|
||||
TRACE_CPUPROFILER_EVENT_SCOPE(AVegetationManager::SpawnSkeletalFoliages);
|
||||
const FTransform HeroTransform = LargeMap->LocalToGlobalTransform(HeroVehicle->GetActorTransform());
|
||||
const FVector HeroLocation = HeroTransform.GetLocation();
|
||||
|
@ -553,7 +548,6 @@ void AVegetationManager::SpawnSkeletalFoliages(TArray<FElementsToSpawn>& Element
|
|||
for (FElementsToSpawn& Element : ElementsToSpawn)
|
||||
{
|
||||
TArray<FPooledActor>* Pool = ActorPool.Find(Element.BP.BPFullClassName);
|
||||
UE_LOG(LogCarla, Error, TEXT("Class %s"), *Element.BP.BPFullClassName);
|
||||
|
||||
if (Pool == nullptr)
|
||||
{
|
||||
|
@ -566,20 +560,16 @@ void AVegetationManager::SpawnSkeletalFoliages(TArray<FElementsToSpawn>& Element
|
|||
int32 Index = TransformIndex.Value;
|
||||
if (Element.TileMeshComponent->IndicesInUse.Contains(Index))
|
||||
{
|
||||
UE_LOG(LogCarla, Error, TEXT("Indice in use"));
|
||||
continue;
|
||||
}
|
||||
const float Distance = FMath::Abs(FVector::DistSquared(Transform.GetLocation(), HeroLocation));
|
||||
if (Distance > HeroDetectionSizeSquared)
|
||||
{
|
||||
UE_LOG(LogCarla, Error, TEXT("Too far from the foliage"));
|
||||
continue;
|
||||
}
|
||||
bool Ok = EnableActorFromPool(Transform, Index, Element.TileMeshComponent, *Pool);
|
||||
if (Ok)
|
||||
{
|
||||
UE_LOG(LogCarla, Error, TEXT("Enabled"));
|
||||
|
||||
{
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -587,7 +577,6 @@ void AVegetationManager::SpawnSkeletalFoliages(TArray<FElementsToSpawn>& Element
|
|||
NewElement.Actor = CreateFoliage(Element.BP, {});
|
||||
if (IsValid(NewElement.Actor))
|
||||
{
|
||||
UE_LOG(LogCarla, Error, TEXT("New element added to pool"));
|
||||
NewElement.Actor->SetTickableWhenPaused(false);
|
||||
NewElement.EnableActor(Transform, Index, Element.TileMeshComponent);
|
||||
Pool->Emplace(NewElement);
|
||||
|
|
Loading…
Reference in New Issue