Download

Help with UPROPERTY in Blueprint editor

Hi, I’m trying to create a C+±derived Blueprint class that I can use to control widgets added to the viewport both in C++ and in Blueprints. I’m having trouble referencing the assets in C++.

I’m currently using two methods and none of them are working correctly in the editor:
Code:


UPROPERTY(EditAnywhere)
UWidget* widgetA;

UPROPERTY(EditAnywhere)
TSoftObjectPtr<UWidget> widgetB;

They are both showing up in the blueprint editor but as soon as I set an asset to widgetA and compile the blueprint, it becomes unset! UE4 deselects my asset from the drop-down menu. Why?

And the second widget (widgetB) doesn’t even let me select my asset. I get an empty list with the message “No results, check your filter.”

Many thanks!

So what is the proper way to reference a widget asset in C++?

Check out TSubclassOf.

Thanks, that worked perfectly.

Blueprint assets are classes not objects - so you need to use either TSubclassOf (will load the object), or TSoftClassPtr (will load when you tell it to).