How to Add a Scene Component in C++?

Hi, yeah an absolutely confounding thing about the engine is you have to use a different call to add or attach a component in constructor vs. at runtime. Kinda ridiculous that they couldn’t just hide all that behind the scenes. :expressionless:

If you add a scene component in constructor it is like this:

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

If you add a scene component in an actor any time outside construction, it is like this:

_zoneVisualizationMesh = NewObject<UStaticMeshComponent>(this, "VisualizationComponent");
1 Like