How to clone a hierarchy or AActors if UnrealEditor does not set ParentActor ? (bug ?)

Hi,

I want to clone by code an AActor hierarchy that I set up in the editor. I’m familiar with c++ and graphics transformations, but fairly new with ue4, and I’m having troubles with the relative transformations of my actors when I clone them :

I have a ‘Base’ Actor with RootComponent and MeshComponent that display a box.
In the editor I attach 4 others ‘SubBase’ actors (that also have RootComponent and MeshComponent also diplaying simple box). I moved SubBase actors 200cm each way from Base actor with the editor.

I’m cloning my Base actor in my code like that :

Base* Base::clone()
   {
        FActorSpawnParameters spawnParams;
    	spawnParams.Template = Cast<AActor>(this);
    	spawnParams.Owner = this->GetOwner();
    	spawnParams.Instigator = this->GetInstigator();
    
    	 FRotator rotation = this->GetActorRotation();
    	 FVector scale3D = this->GetActorScale();
    	 FVector translation = this->GetActorLocation();
    	 FTransform transformParams(rotation, translation, scale3D);
    
    	newBase = world->SpawnActorAbsolute<ABase>(ABase::StaticClass(), transformParams, spawnParams);
           if (newBase) {
              newBase->listSub.Reset(newBase->listSub.Num());
              for (auto it = this->listSub.CreateIterator(); it; ++it) {
		auto sub = (*it)->clone();
		if (sub) {
			sub->AttachToActor(newBase, FAttachmentTransformRules::KeepRelativeTransform);
			newBase->listRooms.Add(sub);
		}
           }

return newBase;
}

I figured out that since my Base actor has no parent actor, it is fine to spawn my copy with SpawnActorAbsolute, and so far it seams to work, I have a new actor with correct location & rotation.

and I’m cloning my SubBase actor in my code like that :

SubBase* SubBase::clone()
{
FActorSpawnParameters spawnParams;
	spawnParams.Template = Cast<AActor>(this);
	spawnParams.Owner = this->GetOwner();
	spawnParams.Instigator = this->GetInstigator();

	AActor *pParent = this->GetParentActor();
	if (!pParent) {
		UE_LOG(GameLog, Warning, TEXT("clone problem : SubBase has no ParentActor !!!"));
	}

	return world->SpawnActor<SubBase>(spawnParams);
}

I simplified the implementations, naming etc.

the problem I’m running into is that in my SubBase actors there is no ParentActor, and all transforms seams to be absolute. (event if I set Attach To from le world outliner)

This is a problem because at the end of my Base clone, I Attach new SubBase to the new Base elements, and they are wrongly offseted with their position from (0,0,0) instead of what should be their relative position to the original Base Actor.

Do you know why editor does not set c++ ParentActor when I AttachTo from editor, and how can I get Relative position in that case ?

Thanks,