Download

Cannot Attach to RootComponent [unsolved]

Hello, I’ve been following the tutorial here

and when recreating the code with a few adjustments, and it compiles fine. When running the program in the UE, I get an error through the editor that says

“root component cannot be attached to other components in the same actor. Aborting.”

I believe the problem is within this bit of code from the tutorial, and this part was unedited when putting it into my program and still doesn’t work.


    RootComponent = CreateDefaultSubobject<USceneComponent>(TEXT("RootComponent"));
    testMesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("TestMesh"));
    OurCameraSpringArm = CreateDefaultSubobject<USpringArmComponent>(TEXT("CameraSpringArm"));
    OurCameraSpringArm->SetupAttachment(RootComponent);
    OurCameraSpringArm->SetRelativeLocationAndRotation(FVector(0.0f, 0.0f, 50.0f), FRotator(-60.0f, 0.0f, 0.0f));
    OurCameraSpringArm->TargetArmLength = 400.f;
    OurCameraSpringArm->bEnableCameraLag = true;
    OurCameraSpringArm->CameraLagSpeed = 3.0f;

    OurCamera = CreateDefaultSubobject<UCameraComponent>(TEXT("GameCamera"));
    OurCamera->SetupAttachment(OurCameraSpringArm, USpringArmComponent::SocketName);

You may need to actually set the root component -
this->SetRootComponent(RootComponent);

Wow it’s been more than 2 years to this question and no UE representative has answered? I got here because I am following the same documentation and the same problem occurs (even if this is just a warning, though the message would then be misleading, this should be corrected)

I would assume it’s because the name “RootComponent” is already being used by the… RootComponent.

Try this instead:


 
 RootComponent = CreateDefaultSubobject<USceneComponent>(TEXT("Root"));