Asset Manager with Packaged Primary Asset Types of UUserWidget

During some R&D with the Asset Manager, I found that the Asset Manager could not find PrimaryAssets of a UUserWidget derived class in packaged builds.

When you create a widget and parent it to your UUserWidget derived class, unreal engine creates Widget Blueprints, which are of type UWidgetBlueprint, which is contained in the UMGEditor module. As such, you cannot use the UWidgetBlueprint class in your runtime packaged builds as it’s an editor only module.

What I didn’t know is that when you packaged Blueprints and Widget Blueprints, the packaging tool strips away the Blueprint and Widget Blueprint classes and you are left with the Generated classes: UBlueprintGeneratedClass & UWidgetBlueprintGeneratedClass, which is the reason the Asset Manager cannot find them as they are not the base class the Asset Manager is looking for in regards to the PrimaryAssetType.

This is where the Asset Registry comes in. Originally, thanks to the documentation (Asset Registry Documentation) quoting

The Asset Registry is an editor subsystem which gathers information about unloaded assets asynchronously as the editor loads.

I thought that it was an Editor Only module and could not be used at runtime. This is not the case and I put it down to bad documentation.

The Asset Registry showed me that my Widget Assets were indeed being packaged… which was a good sign. To register these Primary Widget Assets with the Asset Manager I created this function (With the help of a million posts on the internet & Discord). I wrapped it into a template so I could easily register widget blueprints with different Primary Asset base classes if needed.

I have also included a templated function to get the widget of UUserWidget derived class.

This fix works in packaged builds.

2 Likes