Pure C++

Let’s say I have a large AActor class and I want to divide its functionality. Should I create the different subclasses from UObject or use pure C++ classes using new/delete appropriately? If these classes are only for cleaner code conventions and won’t need to be blueprinted, is it ok to approach it this way?

1 Like

You could use UActorComponents for that.

  • Actor Components (class UActorComponent) are most useful for abstract behaviors such as movement, inventory or attribute management, and other non-physical concepts. Actor Components do not have a transform, meaning they do not have any physical location or rotation in the world.

But in case you don’t want to use UActorComponents, you need to consider if you still want to leverage the reflection system or not. If that’s the case, use UObject. If not, use a normal C++ class.


These pure classes would be deleted at the same time of their parent, which would be using the reflection system, and on its destructor deleting them.

If the actor has multiple meshes you can make C++ component classes that inherit from StaticMeshComponent or SkeletalMeshComponent.

We do this extensively with stuff like panels or consoles that have multiple buttons, lights, switches, etc.

If you want the behaviors you factor out to be discoverable in Blueprints, and contain reference counted pointers to other objects, and contain properties that replicate, or go into savegame, then the classes need to derive from UObject.

If there really are separate areas of concern, then breaking up the functionality into Actor components is perfectly valid. Some Actor components are highly dependent on their “parent” class (see Character movement components vs Character pawn subclass, for example.)

If the areas of concern are really quite separate, then you can build the sub-features using totally separate libraries, and just put a shallow wrapper on top of the library features in your main Actor.

If all of the code just needs to know about all the other code, there’s no real need to break up the actor. Sometimes, you really do need a 5,000 line file. The trick is to keep each separate thing, separate, but not try to over-separate things that really aren’t separate. You’ll just end up causing more harm getting it wrong.