Access to RootComponent not available

Josai
Sat, 04 Nov 2017 14:03:49 +0000
C++

Hello,

I have a Problem with the RootComponent of a class. I try to Get Access of the RootComponent of an AActor with GetRootComponent. Before I tried this I set a BoxComponent as RootComponent. But if I want to get access of the Root I ever get a nullptr. How can I access the RootComponent, because I want to add a force to the object but it doesn’t work without access to the Root.

Short Example Code:
Test.h

class UBoxComponent* m_RootComponent;

Test.cpp
Constructor:

m_RootComponent = CreateDefaultSubobject(“RootComponent”);

//some other Stuff to configure the RootComponent

RootComponent = m_RootComponent;

Other Method:

UBoxComponent* box = GetRootComponent(); // I tried this, because the Root is a box
USceneComponent* root = GetRootComponent(); //I tried this, because the output of GetRootComponent is a USceneComponent

OtherTestClass.cpp (inherits from Test.h)

Method:
UBoxComponent* box = GetRootComponent();
USceneComponent* root = GetRootComponent();

The methods under the Constructor are my tries to get access to the RootComponent, but every try gives me an error with a nullptr. How can i fix it to add a force to this actor ?

Josai.

3 posts - 3 participants