Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Is there any reason to inherit UObject over AActor?

I am moving from to Unreal as a former Unity developer and I am trying transfer my knowledge. For the most part, I am ready to dive in and have a decent idea of how things should be done. The question I posed is the last one to get me started.

In Unity, every game object has a transform, even those that do not need it (sure, you could just create a basic class, but then you wrestle with the component model which just isn't worth it). In Unreal, it seems the same thing would apply, always inheriting from AActor seems to have no downside other than having a root component with transform that may not be used. Are there any other advantages to inheriting from UObject over AActor that I am missing before it bites me later on?

Product Version: UE 4.9
more ▼

asked Dec 19 '15 at 11:02 AM in C++ Programming

avatar image

26 3 6 8

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

UE4 got object and class management system and all objects are are part of it it needs to inherent from UObject, It's part of reflection system so you are not forced to use UObject but then your class won't be visible by the engine and won't be able to be used in many engine features (most impotently Blueprints), most impotently garbage collection won't see it and won't collect it, such classes need to be manually managed in memory with "new" and "delete" (like in raw C++ code), even so i seen uses of such classes in engine code, whole Slate UI framework are outside UObject (thats why it need UMG to be used in blueprints). So for UE4 UObject is most minimal object class, like pixel is most smallest fragment of image.

Main difference between UObject and AActor, as UObject it's just most minimal object code, it does nto have code to place it on the level and thats what AActor have (keep in mind AActor is also UObject class), it has code that ties object with UWorld a world instance and AActors are also managed by UWorld class not only UObject managment systems. AActors themselves are not really physical (i think you already notice that) what makes them physical is components and root component determence it's location, all transform functions in AActor relay on root component and they will do nothing without root component, not to mention not all components are physical, only USceneComponents, there movement components that controls movement of actor, so components are more like plugins for actors. Also impotent difference between AActor and UObject (and reason why nonphysical classes like AGameMode ot APlayerController are AActors) they are integral part of world instance, they relate to gameplay, if world instance get destroyed (you load next level for example) all AActors objects that are tied to that world instance will get destroyed with it, so all AActors are designed to be resetable (thats why AGameMode is a actor, it's tied to world and resetup it self when level is started as all other actors, there UGameInstance class that functions as persistent AGameMode). Because AActors are tied to UWorld instance, it a lot easier to interact with the world from that class using GetWorld() function, also impotent to know because AActors is part of game state (state of world instance), they are only classes that state can be replicate, because they replicate they only one that can be played on demo recording and as well as saved and restored in game saves.

So in short, everything that is tied to single world/level instance, tied to game state.need to be AActor, everything global persistent with game process and independent from world instance (but it can operate it if needed) should be UObject.

Good example is AGameMode and UGameInstance, AGameMode controls manages current world instance and it dies with it, UGameInstance (which is normal UObject) exist beyond world instance and look over all world instances that will be created (usally by informing and controlling AGameMode of current world), also functions as a memory so new world instance knows what happened in last one and beyond it.

You might come to conclusion that UE4 is designed more for multiplayer matches then story expirance, which imo way it is.

more ▼

answered Dec 19 '15 at 05:44 PM

avatar image

37.2k 936 172 1116

avatar image Chazney Dec 19 '15 at 09:22 PM

I see, that cleared everything up that I needed to know. Cheers.

avatar image wellbye Oct 06 '16 at 04:22 PM

very useful!

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question