Can I run Blueprint code using the Class Default Object?

Most of my code is in C++. I subclass my C++ classes to configure the values using the Blueprint editor.

I use Class Default Objects (CDOs) extensively, because I just need a place to put the configuration and I want to avoid the overhead of creating/destroying objects.

I’ve run into an issue where using a Blueprint custom event causes the game to crash:

I thought it was due to my modifying a variable in the Blueprint code, so I removed that and made the class Const, but the crash is still happening.

The GC object that’s having issue seems to be the function itself. This is the log:

Disregard for GC object Function
/Game/MyBlueprint.MyBlueprint_C:ExecuteUbergraph_MyBlueprint
referencing
SomeObject/Engine/Transient.None which
is not part of root set

I don’t fully understand how there could be garbage in this case, as no variables (local or otherwise) are used. It seems like any value that is accessed can cause a problem, even if it’s not explicitly stored.

The conclusion is that it’s not possible to run Blueprint code using the Class Default Object’s pointer. Is this true? Am I interpreting this wrong?

Try creating new blueprint with same functionality maybe your blueprint asset corrupted

I don’t think that’s the problem. I can make the crash go away if I create a new instance of the class before calling the blueprint function. I just would like to avoid that due to the performance hit.

I have found a solution to implement the AddReferencedObjects function and use reflection to mark blueprint variables as CPF_SkipSerialization