USceneComponent With C++

Hi, i’m just wondering how you can give a class a transform. I know i can use blueprint to give the object a transform with the scene component but i would like to be able to add a root component in C++ that can give the class a transform.
I have been looking around and found the USceneComponent but i’m having trouble getting one into my code, anyone have an example for me to try?

// Thanks

The AActor class has a RootComponent property. If you look at a class such as AAmbientSound you can see how a SceneComponent subclass is instantiated and then assigned to the RootComponent pointer. This gives your AActor its position in the world.

Alright i’ll have a look at that, thanks for the help.

Although, do i need to have one of the subclasses? I cannot just have the parent class in order to get a position in the world?

You can use the SceneComponent directly. As it says in its header: " A SceneComponent has a transform and supports attachment, but has no rendering or collision capabilities. Useful as a ‘dummy’ component in the hierarchy to offset others."

I did a quick look and an even more relevant example to your case is in AMatineeActor. Here are the relevant lines:

TSubobjectPtr<USceneComponent> SceneComponent = PCIP.CreateDefaultSubobject<USceneComponent>(this, TEXT("SceneComp"));
RootComponent = SceneComponent;

Alright, thanks a lot! Really helped :slight_smile: