First of all, setting FActorSpawnParameters.Template to an instance of an actor to spawn a copy of the given actor results in the following warning: Warning AttachTo: '/Game/UEDPIE_0_TestLevel.TestLevel:PersistentLevel.BP_ActorToClone_0.TRRoot' cannot be attached to itself. Aborting.
NOTE: TRRoot is the root component of the actor I’m trying to clone.
It also results in a broken actor with duplicated dynamically spawned components and without the child components that were previously defined in the editor.
Here is the code I’m using to copy the actor:
UFUNCTION(BlueprintCallable, Category = "Helper")
static AActor* CloneActor(AActor* actorToClone, const FTransform transforms, ESpawnActorCollisionHandlingMethod collisionMethod = ESpawnActorCollisionHandlingMethod::AlwaysSpawn)
{
if (actorToClone->IsValidLowLevel())
{
UWorld* world = actorToClone->GetWorld();
FActorSpawnParameters params;
params.SpawnCollisionHandlingOverride = collisionMethod;
params.Template = actorToClone;
return world->SpawnActorAbsolute<AActor>(actorToClone->GetClass(), transforms, params);
}
return nullptr;
}
These are the results:
Please note that there are only 2 actors in the last picture - one to the right and the other in the middle at (0,0,0) with duplicated TextRenderComponents to the left.
Would be awesome if you could tell me what’s going on and if I’m even supposed to use instances as templates. Thanks!