How to override the Default Scene Root component with my own in C++?

image_2022-06-13_233741663

In blueprint I can add a new Scene component and drag it on the top of the default Scene Root to override it.
But how to do this in the C++?

Like this:
.h

UPROPERTY(EditAnywhere)
		USceneComponent* DefaultRoot = nullptr;

.cpp

// In Constructor
DefaultRoot = CreateDefaultSubobject<USceneComponent>(TEXT("DefaultRoot"));
SetRootComponent(DefaultRoot);

Result:
image

5 Likes

Create a Scene Componenet and set it the root componenet instead of attaching it.

RootComponent = MyNewScene;

2 Likes

Thank You Sir for the perfect solution, this solution solved the issue

2 Likes

Thank You Sir for the perfect solution, this solution solved the issue.
Both Solutions are perfect, I really appreciated

1 Like

Main thing is the problem is solved :smiley: keep up learning

2 Likes