Creating a custom Class Default Object and correct initialization

Hey there guys,
For our plugin we needed to use a custom compiler that at the end, injects some values on the CDO (a state machine of sorts)
This works very good, but has an issue that i’m pretty sure it’s a configuration one.

When i’m instancing this type of objects, this sub UObjects don’t get correctly copied… this is… they are basically pointers to the CDO objects, what i want is the engine to duplicate them per instance as it does normally, this has issues when wanting to instantiate multiple copies of the dynamic class, as all of them point to the same C++ Raw Pointer.

Now, checking the engine the issue seems to stem from FObjectInitializer wanting to use the UClass->PostConstructionLink for fastest compilation, but this is a null pointer.
As i read, this is a chain of UPRoperties pointing to properties that need PostLoading, so am i wrong to assume that setting RF_NeedPostLoad for the properties is good enough? or am i missing something else?

How does the UClass construct or obtains the PostConstructionLink?
And in that regard… are my assumptions correct on thinking that FObjectInitializer::InitProperties is the place where the SubObject get duplicated to their instances (via property copying)?

Any help would be appreciated… at this point i have only come this far by myself, but i want to understand what i’m messing with.


Tried to go the GeneratedClass route and setting the postconstructionlink, but that’s not it…

I’m at a loss…
Does somebody have an idea on how does the engine “duplicates” subobjects from the CDO? because right now it’s just copy pasting the pointer reference

Just a hint: UProperies have a specifier “Instanced” which does something similar to what you are trying to do as it makes sure every object gets its own copy of an object referenced by the property. I just don’t know what are limitations of this specifier and whether it works for any subobject or only for actor components.

MVP, will check this out… i have a patch that does a deep copying when calling an “init” function, but this is less optimal than your solution.
Will reply here with the results

Also, you can check out the FObjectInitializer::InstanceSubobjects. It looks like this function is doing subobject instancing for instanced properties after the C++ constructor is called.

Instanced UPROPERTY specifier is definitely what you need, it works on any UObject.
Not clear from your question though if you actually have a UProperty on your class pointing to this subobject or not.
If not, you could maybe try adding DefaultToInstanced specifier to the UCLASS macro on your subobject’s class declaration instead.

Yep… figured that i would need DefaultToInstanced, due to the nature of the Object that i’m creating (meant to be used in a per instance manner), haven’i’m actually finishing the polishing of the new version of the plugin and i will now try this approach, which pretty much should work.