Hi guys i have read couple time this thread
But i got some problems with understanding answer…
Could someone clearly and in veeery simple way explain …
What is CDO? How does it work with FObjectInitializer?
How is it connected with UCLASS?
Hi guys i have read couple time this thread
But i got some problems with understanding answer…
Could someone clearly and in veeery simple way explain …
What is CDO? How does it work with FObjectInitializer?
How is it connected with UCLASS?
I want to know too.
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.
So, we cant change the default value in CDO. But I want to modify the default property of some specific asset like particle system when the asset is created. How should I do? I have tried that modified the default property value in CDO of UParticleSystem. But it did not work. There is a fun thing that when I open cascad I can change the property to what I want by click the button called “Reset it to default”.
To do so you need to access object in the asset object, for example UBlueprint for blueprints. I think you already seen this object if you staticly reference blueprint in constructor. Then call Modify() in asset object and editor will mark it as edited asset and allow you to save as well inform you it was modified when you try to exit editor.
I use a delegate callded “OnNewAseetCreated” / “OnConfigureNewAssetProperties”.But this two delegate only has one parameter “UFactory*” How can I accese the object I create by UFactory?
I dont want to modify the engine code. I want to implement this demand by something like plugin. Users can change the default value of property of particle system by a user interface. And when they create a new asset. The property of the new asset will be set to new default value.
It odd it only give you UFactory, UFactory is a classes reproducible of creating asset of particular type, they show up on menu when you right click content browser.
Either way there other event you can hook in to and it is in asset registry which is module managing assets :
https://docs.unrealengine.com/latest/INT/API/Runtime/AssetRegistry/IAssetRegistry/index.html
OnAssetAdded()
and you can access it via FAssetRegistryModule::Get()
Content browser i actully just client of it you can do a lot asset related things from there
Thank you so much! This may be a better way.