Announcement

Collapse
No announcement yet.

RootComponent in actor constructor

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    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.

    #2
    RootComponent is the parent of all components of an Actor:
    https://docs.unrealengine.com/en-US/...ent/index.html

    You can see a better explanation about RootComponent in this video:
    C++ Tanks vs Zombies | 01 | Live Training | Unreal Engine
    https://youtu.be/NyXq0Hy9xQs?t=2602

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

    Code:
    /** 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:

    Code:
    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.
    Using it multiple times in constructor for attaching several components trigger strange behaviours.
    I usually do as explained in the video without problems.

    Comment


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

      Comment

      Working...
      X