Double Rootcomponent

Hi,

Is there something special you need to do when you change the root component of an actor?
I changed the rootcomponent of my cameraclass and it changes the root component (I guess) and but it also adds another one.
This is the constructor

AEnlightCamera::AEnlightCamera(const FObjectInitializer& ObjectInitializer)
: Super(ObjectInitializer)
{
	//Setup root component
	this->SetRootComponent(ObjectInitializer.CreateDefaultSubobject<UArrowComponent>(this, TEXT("Arrow")));

	// Create a camera boom...
	CameraBoom = ObjectInitializer.CreateDefaultSubobject<USpringArmComponent>(this, TEXT("CameraBoom"));
	CameraBoom->AttachTo(RootComponent);
	CameraBoom->bAbsoluteRotation = true; // Don't want arm to rotate when ship does
	CameraBoom->TargetArmLength = 1200.f;
	CameraBoom->RelativeRotation = FRotator(-80.f, 0.f, 0.f);
	CameraBoom->bDoCollisionTest = false; // Don't want to pull camera in when it collides with level
	
	// Create a camera...
	GetCameraComponent()->AttachTo(CameraBoom, USpringArmComponent::SocketName);
}

I made a blueprint that inherits from my class and this is what I get:

29059-untitled.png

I think this->SetRootComponent(ObjectInitializer.CreateDefaultSubobject(this, TEXT("Arrow"))); confuses reflection system try to initiate arrow component in diffrent varable (same as you did with CameraBoom) and then set it as rootcomponent, you can do that just by doing this RootComponent = ArrowComponent;, component initiation procedure just by that will figure that arrow component is root.

I had the same issue and I was just now playing with it.

I even tried to simplify it by just doing

RootComponent = PCIP.CreateDefaultSubobject<UBoxComponent>(this, TEXT("CollisionComp"));

but it didn’t change anything. So what I did was got rid of the Ubox and put a normal object to the root component like a static mesh instead(maybe your camera component would work), to see what would happen, Built it (just let it hot load)and there was no double mesh(root component)!?

I put the ubox back as the root instead of the mesh and hot loaded it again.The double root appeared again but Mesh was still as the top root O.O but the bottom root object was the Ubox . I shut down my UE editor and re built and started without debugging. Lone behold no more double root!

Might have something to do with the order like creating a root AFTER you attach the code to the blueprint ect …but i could be wrong.

All in all it just seems like an aesthetic issue/bug :slight_smile:

I think I found out how the rootcomponent works now I have this:

… Some Code …
RootComponent = ArrowComponent;

… Some Code …
RootComponent = PlayerMeshComponent;

And now player mesh component is the rootchild of arrowcomponent.
Maybe a bit more documentation for the assignment operators is needed here.