which class is best to inherit from?

Hi, I got into unreal engine a few months ago but I still haven’t had a chance to actually do some C++ coding in it so this would be a beginner’s question.
I want to create a manager class that will be in charge of the background layers of a 2d game.
I’m trying to use Paper2D and what I want to achieve is something similar to they repeating background in the TappyChicken example.
But I want to make this system more generic, basically what I had in mind is to have an array of layers where each layer is a struct that contains the layer speed, an array of sprites that makes that layer and a start and end location.
My question is what is the right class to inherit from? should I just make an empty C++ class which will include all the different UE4 classes or am I best to inherit from Actor?

Thanks for your advice,



This is a question that I am interested in as well. If your class is not directly placed into the world, I would instinctively think that a UObject would be appropriate. The problem I have run into is that I have not figured out how to initialize UObjects in UE 4.7 … for this reason, I have been using Actors for my classes …


There are a lot of good resources that should be able to help you figure out which your base class should be.
I would really recommend checking out the links I’ll provide at the bottom of this post. If you have already checked those out and still feel unsure, maybe this way to think about it might help?

Derive from nothing and do a plain old C++ object when you want full control over the lifetime of the object or you don’t want the overhead or the features that the UObject system provides.
Derive from UObject when you want to make objects that you want to be able to customize from the editor layer, or when you want to opt in to the features associated with UObjects such as garbage collection, network marshalling, serialization etc.
Derive from AActor if you want the ability to easily inspect / tweak an object when designing your game and/or it is an object that should have some type of presence in your scene.
Derive from APawn when you want objects that can be controlled by AI or a player.
Derive from ACharacter when you are creating something that behaves like a complex organism like a bipedal.

There are a few other classes that kind of makes sense to derive from in some cases, but in 95% of all cases, one of these should be your choice.

I would probably go for an AActor in your particular case since being able to inspect its state easily from the world outliner when running play-in-editor is worth it.

Regarding Monkn’s question, check out the first link below, although the quick n’ dirty version is:
When you want to create a UObject in runtime, use:
ConstructObject if you are not sure what you might need, this will run the full construction chain for the object.
NewObject if you are ok with doing the rest of the initialization yourself when you deem necessary.

Check out this for how you construct UObjects in runtime!

Everyone should REALLY read these carefully!

I hope this makes it clearer for you guys.

Best regards,

Thank you for the response and links, Temaran. That helped me out a great deal and I’m now creating UObjects at runtime :slight_smile: