This is what’s known as the ‘class default object’ (CDO), and is central to how the UObject
system works. Every UObject
-derived class will have one created at startup.
You can test whether an object is the CDO by doing:
if(HasAnyFlags(RF_ClassDefaultObject))
Generally, you should avoid doing any setup in a UObject
constructor other than simple property initialization and default subobject creation. Heavy setup, and anything that relies on other objects, should be deferred to some later override, or a custom initialization function. In this function, you may want to do a test and skip the logic if it is the CDO. That way, when the CDO gets destroyed, it won’t have setup any resources so a simple check of a member variable should tell you there is nothing to release/disconnect from.