RootComponent in actor constructor

Why RootComponent is used in https://docs.unrealengine.com/en-US/…art/index.html as SetupAttachment argument?
In constructor it seems it’s always null even after the first SetupAttachement.

Using it multiple times in constructor for attaching several components trigger strange behaviours.

RootComponent is the parent of all components of an Actor:

You can see a better explanation about RootComponent in this video:
C++ Tanks vs Zombies | 01 | Live Training | Unreal Engine

If you don’t set a value for it Unreal will do it for you. You can see it in Actor.cpp:


/** Util that sets up the actor's component hierarchy (when users forget to do so, in their native ctor) */
static USceneComponent* FixupNativeActorComponents(AActor* Actor)
{
    ...
}


That is called in:


void AActor::PostSpawnInitialize(...)
{
    // General flow here is like so
    // - Actor sets up the basics.
    // - Actor gets PreInitializeComponents()
    // - Actor constructs itself, after which its components should be fully assembled
    // - Actor components get OnComponentCreated
    // - Actor components get InitializeComponent
    // - Actor gets PostInitializeComponents() once everything is set up
    //
    // This should be the same sequence for deferred or nondeferred spawning.

I usually do as explained in the video without problems.

Thank you, I hoped this kind of explanation could be found in the documentation :slight_smile: Perhaps I should think about the source code as a good source of information.