Hi guys.
I’m having a problem with destroyed actors still showing in the scene outliner after they are destroyed (and the associated actor counts are constantly increasing).
They are stored as:
// the actual 2D grid, in this case stored as a 1D array
TArray< TWeakObjectPtr<AActor> > LevelGrid;
I’m spawning the actors with:
FVector loc = GetTransform().GetLocation();
loc.X += (float)xpos * GridSpacing;
loc.Y += (float)ypos * GridSpacing;
FActorSpawnParameters params;
params.bNoCollisionFail = true;
params.bNoFail = true;
AActor * pActor = GetWorld()->SpawnActor(ActorArray[0], &loc, NULL, params);
LevelGrid[GridWidth * ypos + xpos] = pActor;
I’m cleaning them up with:
// clears the grid of any cells (by looping over all cells and if there is a valid AActor *, calling destroy and nulling it out)
void AASimpleGenerator::ClearGrid()
{
for (uint32 i = 0; i < (uint32)LevelGrid.Num(); i++)
{
if (LevelGrid[i].IsValid())
{
AActor * pActor = LevelGrid[i].Get();
if (pActor != NULL && pActor->IsValidLowLevel())
{
LevelGrid[i].Reset();
//pActor->Destroy();
pActor->K2_DestroyActor(); // todo: confirm this usage?
pActor = NULL;
}
}
}
// tell the garbage collector to delete stuff we just destroyed (we no longer have a pointer to them theoretically)
GetWorld()->ForceGarbageCollection(true);
};
What I’m seeing is an expanding number of “Destroyed Actor” values in my scene outliner and an increasing actor count (this is a procedural content generation system and I’m resetting the grid to demo different algorithms).