RealDocs

AActor::SetRootComponent

function Engine Since 4.0
#include "GameFramework/Actor.h"
Access: public

Description

Promotes the given component to be this actor's root component. Returns true on success, false if the component is not owned by this actor.

Caveats & Gotchas

  • The new root component must already be owned by this actor (i.e., GetOwner() == this). Passing a component owned by a different actor will fail and return false without logging an error, so check the return value.
  • Changing the root component at runtime can invalidate cached transform data in child components. If physics simulation is active, consider re-registering the component hierarchy afterwards.

Signature

ENGINE_API bool SetRootComponent(USceneComponent* NewRootComponent);

Parameters

Name Type Description Default
NewRootComponent USceneComponent* The component to promote to root. Must be owned by this actor.

Return Type

bool

Example

Swapping the root component at construction time C++
AMyActor::AMyActor()
{
    USceneComponent* NewRoot = CreateDefaultSubobject<USceneComponent>(TEXT("NewRoot"));
    if (SetRootComponent(NewRoot))
    {
        // NewRoot is now the root; old root is detached
    }
}

Version History

Introduced in: 4.0

Version Status Notes
5.6 stable

Feedback

Was this helpful?

Suggest an edit

Select a field above to begin editing.