I set up a component that debugs all the constructor/functions and I found that when I place an actor blueprint that has this component in an empty world and hit the PIE button (Standalone) I get this log:
First of all the [Default__APLogExecutionOrderComponent] instance is created, what is this exactly? Is the master copy of the component?
Then after the engine is initialized a [APLogExecutionOrder_GEN_VARIABLE] is created. What is this GEN_VARIABLE instance exactly?
Then a [APLogExecutionOrder] instance is created (I think this is the one that will be attached to the actor).
Then you can see a lot of register/unregister/Destruction and ANOTHER construction of [APLogExecutionOrder] :S. Why? I donât understand this flow⌠very confusing and I canât find documentation about component functions flow exactlyâŚ
Archetype Class - this is a âskeletonâ of your C++ Class + Generated Code (Unrealâs Reflection System)
Default Object - this is the âgenerated classâ the engine creates every time you run it, thereâs always a âClass Default Objectâ or âCDOâ; This is where youâll see âGEN_VARIABLEâ thingies.
Instanced Object - this will âspawnâ in game world and copy default values from CDO once created (expose on spawn stuff, etc).
So the code youâve created there is actually running on at least three places at same time.
You can easily check which âversionâ of your object youâre dealing with using something like:
Why the register/unregister/destruction and another construction and again onregister/unregister/onregister before the initializeComponent? (I assume that this is the Instanced Object) I will have to check the flags.
The Editor create/destroy objects when initializing Worlds⌠Some object might be created, but is referenced by nothing then itâs GCed.
And Editor might initialize Worlds multiple times, depends on the tools youâre using to place actors, edit an asset, etc.
Usually you will see PostLoad() called only once on every Editor startup, but PostInitProperties() will be called on Editor launch and also execute every time you click the âPlay()â button and on packaged game.
(because the âCDOâ will always be created on Editor launch and its Constructor is executed every time for each class)
Aha, but why the constructor is called multiple times? I though that the constructor is ONLY called in editor/game startup to create the CDO (GEN_VARIABLE) but as you can see here is called more than one time⌠why? I donât understand then what exactly is the CDO if the constructor is called for every instanced objectâŚ
Didnât see it mentioned, but is the âcontent browser previewâ construction of classes sent to the general log as well? Or is that editor preview created by some different method?
If your Blueprint Class is a regular, common, Blueprint⌠then what you see on Content Browser are âpackagesâ containing the âClass Default Objectâ.
Their Constructors are called during that little %0-100% loading splashscreen before the Editor opens in full.
(yes they will run the Constructor function and output those logs too)
However itâs possible to create assets containing UObjects that are not Blueprint Generated Classes in anyway, so that may vary by a lot, depends on the class.
Without a CDO there is no way for the engine to create instances of the Class.
Your C++ Class is precompiled into that generated Class, then spawned instances are copies of it.
When you package a game, your C++ code doesnât exist anymore; so a precompiled CDO is needed for each Class where instances will copy default values from.
Epic added to Blueprints that special graph that executes when new class instance spawned (trying to emulate C++ Class Constructor).
Internally Unreal executes a call to that graph once âSpawnActorâ routine was successful for that instance;
Behind the scenes that graph is a Function Graph. Function Graphs are Objects auto generated and attached to your Blueprint Class that donât really exist in the C++ version of your Class⌠So you can add functions to Blueprints using the Blueprint Editor while your C++ Class has no idea at all that such function exist on the Generated Class (Blueprint Object).