Download

Call UMG function from C++?

So guys, how do I call a UMG function from C++, and more importantly how do I make variables with type of the custom UMG widget

Let’s say I want to call SetMessage() in UMG widget FullscreenNotifyWidget which is a custom widget


/** Displays full-screen notification overlay
 *
 * @param Message		Notification message
 */
void UDHGameInstance::NotifyUserFullscreen(FText InMessage)
{
	const NotifyBoxFullscreen* Widget = Cast<NotifyBoxFullscreen>(FullscreenNotifyWidget);
	if (Widget) Widget->SetMessage(InMessage);
}

In this case, how do I implement that?

I would use events. Define the delegate in C++ and then bind to them in your UMG widget. Then you can raise that event from either C++ or from a blueprint. Forum member WCode did a good tutorial on delegates here.

Either you go the delegate way like snidersh told you, or you create your own Widget BaseClass in C++ and then let the Widget Blueprint inherit from them (Reparent them after creating them).

If you search the forum/google, you can find thread about creating WidgetsClasses in C++ and how to use them. There you can just create an event that you can call in C++ or the BP version of the
Widget if you expose it.