I’m new to C++ in Unreal, but have coded in C# for a long time. I learned how to attach static meshes to a RootComponent in C++, but I can’t figure out how to attach another C++ class to a RootComponent. Below is the code I have. I took most of it from the classes I’m taking, but the MazeWall class I created doesn’t have a SetupAttachment function like the static mesh does. How do I attach another class to a root component so it will have it setup in the BluePrint?
For setup attachment you also need to pass in FName which is the socket name.
EDIT: actually you don’t.
That’s above my head a bit, can you show me an example?
Ooops wait, your code looks correct. You don’t have to also specify socket.
Assuming those components are proper scene components, that should work.
Did you include all the classes at the top of the CPP file?
Actors should not be default sub-objects. Default sub-objects are for UObjects that are not Actors.
Generally in an Actor constructor, you’re creating ActorComponents. Scene Components (like StaticMeshComponent) have attachment support.
What do I have to change to make this work? Do I need to put static meshes in instead of an actor?
Maybe, it’s hard to say based on the limited set of code that you’ve shared.
Yes, you could make those static mesh components instead. You might also be trying to build something in code that should really be a map with actors. I couldn’t say.
Sharing more code probably won’t help. You’d have to describe what it is you’re trying to build and the pieces you’re trying to make to get you there.


