UMG Blueprint to C++ Conversion

Hello Friends,

I’m currently trying to convert my UMG Blueprint Widget into a C++ class and was wondering what the best route would be to do this? To provide some context, I have a UMG blueprint that has multiple overlays, a background image, and a slate brush under a canvas panel. I use an EventGraph to update the position of the slate brush relative to the player controller world position. I also have a OnMouseButtonDoubleClick that gives me the position of the mouse relative to the minimap all in blueprints.

Does anyone have any recommendations for what class I should go with to convert this into C++? Should I create a Blueprint Function Library to create one large Widget node and expose that to the UMG event graph. Or should I go with the Slate Widget class and try to construct everything and expose all functions without UMG? I’m a bit of a UE4 C++ noobie if you can’t tell, and I would love the advice!

Thank you for your time!

Thanks for the info Dune! I’ll give this a try

I’ve found that when creating menu systems, the best approach is to create the base class in C++, and then parent the blueprint UMG widget to that.

I’d create a C++ class with its parent as a UUserWidget (class MY_API UMyWidget: public UUserWidget). In here, you can create the tick function (NativeTick for Widgets) and do you tick logic in here instead of the blueprint.

For the actual Background Images, overlays and other widgets, I’d leave them in the Blueprint as it is much easier to manager there. If you do want references to them in C++, I found the best way is to create a variable with the same name in code and use “meta = (BindWidget)”. This will link the blueprint variable to the code variable.

UPROPERTY(meta = (BindWidget))
class UCanvasPanel* MyCanvasPanel;

You can also look at hooking up the Mouse events on the widgets if you like, but this can be more in-depth and is probably easier to get to grips with in the blueprints if you are quite new to the UE4 C++. The API reference to the C++ function is here though: http://api.unrealengine.com/INT/API/Runtime/UMG/Blueprint/UUserWidget/OnMouseButtonDoubleClick/index.html

1 Like