CDO is Class Default Object, in that anwser i said it is for perfomance but i was kinf of wrong, main function of it is store default state of the object of class and hold default variables states. Each UObject class marked with UCLASS() you make in C++ is registered to reflection system.
What is reflection system?
C++ is compiled to CPU machine code and CPU don’t know concept of classes or varables, classes are just information for compiler how to set up the CPU code and variables only turn in to memory addresses, co CPU don’t know about class existance or else software it self keep track of that, and so i case of UE4 it is reflection system, so you code see reflection of it self. UE4 has a special tool called UnrealHeaderTool which gethers those dummy macros that oyu make UPROPERTY, UCLASS, USTRUCT, and generate extra C++ code which registers classes function and propeties to reflection system, this way enine see those things and keep tracks of them. each element in reflection system registry have UField object created
which represents the thing in the code and it stores information about it. Each UObject class have UClass object which you can get using GetClass() or StaticClass() i bet oyu already seen those.
So back to main topic and i try to hold it in points so you understand more
-When UClass object is created for class the CDO is created for that class and stored in that UClass to hold information on defaults.
-UClass is created when code module is loaded, which in most use cases (or else you dynamicly load code modules) is when engine initiate. Obviously this also happens when you do hot reload as you module is reloaded
-Because CDO is created in early stage on engine and objects as well of actors have extra initiation code that need to be executed to make them functional, you should not talk to engine or gameplay code on constructor as you might have a crash if you do so due to fact not everything is initiated.
-Constructor should only set varables to there default state, as result they will be applied to CDO and engine will acknolage there default states
-CDO should also not be modified or do any functions that change them because it might confuse engine and editor code and result in to some unexpected .
-FObjectInitializer is object that hold information what to do after constructor
-Constructor is naturally called right after object is allocated in to memory, it is something that engine have 0 control over it because this is how C++ compiler set things up. So this object hold some extra settings what UObject and Actor initiation code which will be called after constructor should do.
I can’t write it simpler. Generally you should not care about it so much or else you really in to it other then few facts:
-CDO primerly function is to hold defaults, so if you want to access defaults of your class you access CDO from UClass and get varable
-Creation of CDO on enigne init will execute constructor of your class on engine init, so if you do something wrong in constructor it will crash engine on start.
-Because constructor is called in early stages of the engine initation and object it self, you should not do any gameplay execute code, because most likely you will have a crash. Use diffrent event in class for it like PostInitPropeties (called after changes made by blueprint system is applied in object) PostInitComponents (called after components in actor arei nitiated) or BeginPlay (when actor is fully initiated). Note that 2 first events are also called then you palce actor in level editor.