A change just went into the engine today to let you get the ClassDefaults from a class variable reference in blueprints. It will probably be a while though before a release includes it. There’s an experimental naive implementation below if you can’t wait.
All you need to do is store a reference to an objects CLASS somewhere and not store the actual object. In that way you can create data structures that use “data only blueprints” to define data that can be used in your scripts.
For example I just got done making a radial menu system using data-only BP widgets. Each asset is a BP of a custom UIWidget class, and each has a struct of info similar to what you have. Such as the widget name, enums for functionality etc. An array of ‘child’ widgets. In that way the system can destroy and re-create any menu depth by getting defaults from the classes.
Ie, if the user selected “Place Objects”, all current widgets get destroyed (and I use a “struct” of components for that), then the selected widget children get read as simple class references. Then the BP can create each of the widgets from that data at each step. The nice thing about a system like that is the final menu rendering BP doesn’t have to know much of anything about the menu structure and it doesn’t need ANY references to start other than a Root Widget link (and the root’s only settings are its list of children since the rest never gets used).
It will probably be a while before that change makes it to an approved build. I am actually on a separate project that does not have the changelist merged yet so I added a VERY PLACEHOLDER BP node to get class defaults. It can be risky since it will give you the ability to WRITE to the default object which you should NOT DO.
If you need to set up a workflow like this and cant afford to wait a few months here is all you need.
I added this to “KismetSystemLibrary.cpp” and .h.
Add to KismetSystemLibrary.cpp (or any of the kismet library files):
//@TODO RYAN REMOVE THIS TEMP FUNCTION AFTER PHILLIP Ks PROPER VERSION IS CHECKED IN!!!!
UObject* UKismetSystemLibrary::GetDefaultObject(TSubclassOf<UObject> ObjectClass)
{
if (ObjectClass)
{
return ObjectClass->GetDefaultObject();
}
return nullptr;
}
Add to matching .h file:
//@TODO RYAN REMOVE THIS TEMP FUNCTION AFTER PHILLIP Ks PROPER VERSION IS CHECKED IN!!!!
UFUNCTION(BlueprintCallable, Category = "Utilities|Object")
Warning once again that this code is experimental and probably can do dangerous things if you do anything besides “Get class defaults”. You still have to cast with this node.