Best way to update a widget

I have a problem on finding a way to detect change to update something on my widget. For example, I am trying to change a button on my widget on the fly so the player would know which button they are on when they navigate the menu. I tried a Set Timer by Event command and that was a big mistake coz it still activates even when the widget is hidden/collapsed. What command should I use for this?

For communication from game to widgets:

Create and use BP_HUD. Single place to keep all logic for user interface.
Then add event dispatcher there, that is basically a message.
It should have ENUM that identifies which widget it is for.
And “payload” as string (because you can change any value to string and from string)

Then make all widgets hook to that dispatcher in hud.
send who is target widget (with enum)
and in each widget make logic that parses payload string.

Another way (on text widget example).
For widgets that contain another widgets (like list of strings):

  • create custom widget that displays string/text
  • in it make event (or function) that sets text value (color and whatever you want)

In widget that holds list of those sub-widgets make array of them and for each loop, then call that event function to set values.

So for your buttons example:

  • create your master widget with all buttons (name them make them variables)
  • create array of those buttons that holds them all (so you can use for each loop later)
  • detect/make logic for which button is selected
  • then set that button state trough event/function like i described above

For selecting those buttons you can use same method like in dispatcher:

  • make enum, and exposed variable that keeps such enum in each button
  • when you want to change state of some button, in for each loop trigger event setting state. If enum value sent to button is equal to enum value in that button then change state to TRUE/visible etc, if not equal collapse it.

I think I’m already done with the step you are telling me. I already made arrays of the buttons and a custom event to call to change the buttons’ appearance when it has keyboard focus. What I’m asking is what command/node should I use so the widget will update every time the player presses a button or some way. For example, I can’t use Event Tick(which only runs when the widget is visible but it runs way too many times a sec) nor Set Timer by Event(which can be customized in seconds but runs even when the widget is collapsed/hidden).

If I’m wrong and you actually addressed my problem, can you please make an example Blueprint with screenshot so I can better visualize it. Thank you

Make some “message bus” dispatcher for eg in BP_HUD or player controller etc.

  • create enum that says who is receiver of message (or gameplay tag, or just name)
  • create dispatcher that has that enum, and string as message/payload in BP_HUD
  • every button or widget or player action, etc. (everything that is input), triggers that dispatcher in BP_Hud, set reciever, and convert to string what is payload (like floats, int messages)
  • every widget that needs to display info assigns event to that dispatcher in hud, checks if its designated receiver, then interprets (converts) payload string

this way you will trigger update only when there are changes in hud.

There is no single node that make all widget communication. You should use dispatchers and events, like in that “message bus” i just described

ps.
for umg etc, do “slow tick” in some blueprint like game mode or game instance create dispatcher that “ticks” every 0.2 sec or so (this is plenty for game hud). then use that slow tick to check and update events in widgets (for continuous things like location direction, map etc.)

pps.
that “reciever” enum may be type of info for hud widgets like “health” “ammo” etc.

1 Like

Personally, I like to use an interaction interface it makes it incredibly easy to call actions on other blueprints.

But if you are needing help referencing, you should create a variable reference to it when the widget is created on your character and then call that reference when you need access to it.

I just used Event tick with low delays to update Widgets and it seems to work fine.

That is bad idea, you should not use event tick for such stuff (things that can be done without tick). Instead of tick trigger update from input events.

Why?

Because event tick is heavy on resources, and soon or later you will try to optimize your game, so why adding that on tick (even with delays) when you will change that later anyway? Just do it now when you are at this code.

But I tried a print string and it only runs when the Widget is open and fortunately, the Widgets are not open all the time. Also, isn’t Binding(which I use all the time) also Event tick? I just read it in the past and I don’t know if it’s correct.

Its just best to avoid both event tick and binding. Just update what needs updated at the time of alteration. No need to keep it constantly checking for changes.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.