How can I communicate between my BP and UMG?

So, I’ve created a UMG widget that is acting as a scoreboard HUD for my game. I have an actor in my game that when it is interacted with I want it to fire a message to the scoreboard to update the player scores. I tried doing this using an interface, and even though the “scoreGain” interface message fires from the actor the “scoreGain” event does not fire in the scoreboard widget.

Alternatively, I’ve tried to cast directly to the scoreboard widget, but I can’t find a cast node for the widget. What is the most effective way to communicate with widgets?

I can post some images of my blueprints, but at the moment I’m not even sure what would be helpful to see. Any help is appreciated!

Hi Kapos,

The way I communicate to UMG is through the Actor which owns the UMG Widget. You want to do this too because the UMG Widget is a component added to the Actor, thus does not have Context of the world. Making it difficult for the UMG Widget to be communicated to by objects of the World which have Context to things such as Game State. I notice this when trying to assign events from the World to the UMG Widget. Nothing from the world communicates to the UMG Widget properly from what I’ve seen. So since the scoreboard is viewed by the individual player, that Pawn owns that Widget, should communicate for that Widget. So what I suggest is updating the Widget when the Pawn is notified the score has changed. You can do this by adding an Event Dispatcher on the Pawn itself. This now allows you to use other Actors of the world to communicate to your UMG Widget indirectly through the Player Pawn.

If you want I can demonstrate how this done!

Thanks,

Peter L. Newton

The simplest way to communicate with a widget blueprint is to keep a reference to the widget in the Actor in charge of the widget. For instance if you add the widget to the viewport in your PlayerController blueprint, you can create a variable of type ‘MyWidget’ and set it when you add it to the viewport. Now you can directly call functions on that widget blueprint, acces its public variables… anytime. You could go for a more sophisticated approach as SilentX pointed out, but I would avoid doing so unless you have an actual need for it. Keep it simple!

Thanks for the reply! The problem with this is that my Widget is being called by “MyGame” and isn’t owned by any actor. It’s a single screen local multi-player game, so there is one scoreboard for the whole game, rather than for each player. Is attaching the widget to an actor the only possible way to communicate with it?

Thanks for the reply! The problem with this is that my Widget is being called by “MyGame” and isn’t owned by any actor. It’s a single screen local multi-player game, so there is one scoreboard for the whole game, rather than for each player. Is attaching the widget to an actor the only possible way to communicate with it?

I see your situation. – Yes, you have to create an Actor with the UMG widget attached. For example, if you created a 3D Widget Actor. That Actor should be able to communicate for the UMG widget.

Yes, but you don’t need to do this in the PlayerController. It can be anywhere, just make sure it’s in a blueprint you can easily access. In your case the GameMode or GameState blueprints might be more appropriate places to store the reference to your widget. Where you create the widget and store a reference to it. Any communication to the widget now flows through this Actor. Now you can call functions on your widget, set its variables etc. from anywhere using Get GameState/GameMode and a Get Variable node.

EDIT: See this link for an example on how to create the widget, keep a reference to it and add it to viewport: https://docs.unrealengine.com/latest/INT/Engine/UMG/QuickStart/4/index.html

Relevant image from article:

https://docs.unrealengine.com/latest/images/Engine/UMG/QuickStart/4/UMG_Update26.jpg

You could use the GameInstance Class to store it. Just create a new Blueprint and take “GameInstance” as parent class. Now go into the Maps/Nodes of your Project, where you normaly set the GameMode/Player/Controller/HUD Class and scroll down to the bottom. There you can set your custom GameInstance class.

Here you could create the Widget and save it, likettondeur said and showed above. You can access the GameInstance by just using “Get Game Instance” in any Event Graph.

This did it for me. Thanks guys! Much appreciated.

Thanks!, I had the same problem! :smiley: