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!
asked Jan 10 '15 at 07:24 PM in Blueprint Scripting
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!
answered Jan 12 '15 at 11:02 AM
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!
Peter L. Newton
Follow this question
Once you sign in you will be able to subscribe for any updates here