x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

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!

Product Version: Not Selected
Tags:
more ▼

asked Jan 10 '15 at 07:24 PM in Blueprint Scripting

avatar image

Kapos
16 4 6 9

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

2 answers: sort voted first

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!

more ▼

answered Jan 12 '15 at 11:02 AM

avatar image

ttondeur
16 1 2 6

avatar image Kapos Jan 14 '15 at 05:23 AM

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?

avatar image ttondeur Jan 14 '15 at 10:28 AM

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: UMG Add Widget to viewport

avatar image eXi Jan 14 '15 at 02:06 PM

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.

avatar image Kapos Jan 15 '15 at 06:40 PM

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

avatar image Nicorepe Apr 30 '15 at 01:39 AM

Thanks!, I had the same problem! :D

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

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

more ▼

answered Jan 12 '15 at 03:03 AM

avatar image

PeterLNewton
2.1k 75 37 111

avatar image Kapos Jan 14 '15 at 05:23 AM

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?

avatar image PeterLNewton Jan 14 '15 at 09:15 AM

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.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question