How to destroy attached actors when parent actor gets destroyed?

Hi, as title says I can’t figure for the life of me how to do that, I’m trying to have all the spawned actors be destroyed when the parent is destroyed/deleted/cut inside the editor.

Inside the BeginDestroy() function I tried to clean up my TArray of saved actor pointers. But it turns out when BeginDestroy() is called the engine already for some obscure reason cleans up every pointer pointing to actors inside it.

void ALevelGenerator::BeginDestroy()
{

	UE_LOG(LogTemp, Log, TEXT("%d"), Rooms.Num());

	Clean();

	Super::BeginDestroy();
}

So I tried using GetAttachedActors, but this resulted in the exact same behavior, the function returns an empty array when BeginDestroy is called (returns a full array when called prior).

void ALevelGenerator::BeginDestroy()
{
	Clean();

	TArray<AActor*> Attachees;
	this->GetAttachedActors(Attachees);

	for (AActor *Attachee : Attachees) {
		Attachee->Destroy();
	}

	Super::BeginDestroy();
}

This is driving me nuts, I don’t understand why the behaviour would be to start cleanup before calling this function, isn’t the point to let the class manage it’s own clean up?

Thanks

Call you code to destroy attached actors before calling Destroy() function of you actor. I guess when you call Destroy() all attached actors detach from the actor.