Add components to an actor [C++]

Hi!
I want to create a new actor and add some components to it, e.g. a StaticMeshComponent. However I can’t find any working examples or documentation how to achieve this. Does anyone know how this can be done in C++ and not with the blueprints?

The background is that I’m about to model a grid based RTS navigation system and planing to implement actors that will represent units. The units would therefore need a representation in the world and some other custom logic.

#UE4 C++ Wiki Page

I have a wiki tutorial on exactly this!

Adding Static Mesh Components to an Actor in C++

A new, community-hosted Unreal Engine Wiki - Announcements - Unreal Engine Forums,Making_Native%26_Deferred_Attached_to_Socket

Rama

Thank you!

That worked great. I have some follow up questions though. Now I can see the model but I can’t move it around in the editor. JoyfulControl->AttachParent = Mesh; didn’t compile for me so I commented that out so maybe that’s why or should you add a SceneComponent to the actor as a root component?

I typed static ConstructorHelpers::FObjectFinder StaticMeshOb_AW2(TEXT(“StaticMesh’/Game/TestMdl’”)); but why did the example type …"/JoyControl_WindTurtle.JoyControl_WindTurtle" and not just “JoyControl_WindTurtle”.

And finally what function does the name parameter have in CreateDefaultSubobject, must i be unique per world, actor or not at all?

Try AttachParent = RootComponent;

:slight_smile:

to get the right reference, find the asset in the editor, and use right click Copy Reference

Sorry I cant answer all the questions right now.

:slight_smile:

Rama

PS: make a separate post for whatever you cant figure out on your own :slight_smile:

Okay, thanks a lot for the help!