Hello. I am following the tutorials and, in the “on your own” chapter, I am wanted to learn how to attach complete actors to actors. I have managed to attach an actor to actor by spawning the actor I wanted to attach and attach its root component to the actor to be attached on. But the problem is, when this process is finished, I get two actors which I spawned instead of one.
Here is the code:
MyActor::MyActor() { // Constructor
// Spawn an actor and attach its root component to this actor
UWorld* ThisWorld = GetWorld();
if (ThisWorld)
{
FActorSpawnParameters SpawnParameters;
SpawnParameters.Owner = this;
SpawnParameters.Instigator = Instigator;
FVector SpawnLocation = GetActorLocation() + FVector(100.0f, 0.0f, 0.0f);
AOrbitingActor* NewOrbitingActor = ThisWorld->SpawnActor<AOrbitingActor>(SpawnLocation, GetActorRotation(), SpawnParameters);
NewOrbitingActor->AttachRootComponentTo(RootComponent);
}
}
I get the spawned actor attached to my actual actor, plus I get one another spawned actor which isn’t attached to anything. I don’t want this extra spawned actor. How can I prevent this? Is this a bug?