Is there a way to add a lamda to the UMG widgets events?

I wonder if there is some way to add lambda to the UWidget events, like it works with Slate. For example, in Slate I can do the following:

SNew(SButton).OnClicked_Lambda([]()->FReply{ LoadLevel(TEXT("MainMenu")); return FReply::Handled(); })

However, with UWidget I only have Add and AddUnique methods to add delegates. It is extremely inconvenient to declare a function for every trivial action. :frowning:

It appears that it’s impossible to use lamdas with UWidget after all, which is very sad :frowning: Maybe someone knows, if devs have any plans to make it possible in the near future or UMG will remain as a BP-only feature and continue to ignore C++ usage?

No plans - UMG’s available delegates are dynamic delegates, which means they are ScriptDelegates under the hood. ScriptDelegates can only callback to UFunctions on UObjects, which precludes using them for lambdas.

UMG isn’t designed to replace Slate at the C++ level, if you’d primarily prefer to author your UI in C++, you should use slate directly. If you’d prefer to keep the design in UMG, but the logic in C++, I would suggest making UUserWidget derivatives that define the functions, and hook them up to events in the designer.

Thank you for the answer, Nick.

I’m currently keeping the design in UMG and the logic in UUserWidget derivative class, just as you said. However, I don’t use the Event Graph at all, so there is no point in declaring any UFUNCTIONs in my case. While I understand that your primary focus for UMG is to make it work with BP, it is very sad that you completely ignore cases, when someone wants to write logic in C++ and still use the UMG for design.

I’ve used to work in Unity before, and there wasn’t any problems with using their new GUI designer and still write logic in C#. It is very sad that UE is inferior to Unity in that matter…