(Bug?) Spawned Actors Sneaking Out of a TArray in OnConstruction()

I have an ParentActor with a TArray of Actors

UPROPERTY(EditAnywhere)
TArray<AExampleActor*> ActorList;

I call OnConstruction and everything almost works fine except…

void OnConstruction(const FTransform& Transform)
{
	if (GetWorld() && ActorList.Num() == 0)
	{
		for (int Actor= 0; Actor< NumActors; ++Actor)
		{
			FTransform Translation = CalculateTranslation(Actor);
			FTransform SpawnTransform = Transform + Translation;
			AExampleActor* Tile = GetWorld()->SpawnActor<AExampleActor>(SpawnTransform.GetTranslation(), SpawnTransform.GetRotation().Rotator());
			AExampleActor->AttachToActor(this, FAttachmentTransformRules(EAttachmentRule::KeepWorld, false));
			ActorList.Add(Tile);
		}
	}
}

I get one group of actors which are connected to the ParentActor as expected but I also get a second group of actors spawning which seem to have forgotten they have any attachment to the Parent . From the debugger it looks like this group is created when I initially click on the ParentActor in the editor but before I have dragged it into the world yet. Is this the expected behaviour?

Thanks

I’m not sure but I think Actors get garbage-collected if they’re not placed or spawned into the World.

I have the same issue! Did you figure out the solution?

Check for the transient flag which is set on preview actors. i.e. this->HasAnyFlags(EObjectFlags::RF_Transient)

Wow this worked, thanks for coming back with an update! How on earth did you figure out this was the issue though?