What is the best approach to refresh / rebuild widget's event construct?

The game I’m working on has collectables (“CollectableBP”). PlayerHUD is loading “CollectablesIndicator” widget which should update text if the certain criteria upon pickup is met.

Example: “You don’t have enough items X”, “You need one more item X”, “You have all the items you need”.

I’m currently using EVENT TICK (instead of event construct) inside my widget’s blueprint, because it constantly triggers the widget’s logic. It is working great but I’m aware that this is not the right approach. I would like to make my CollectableBP communicate with the widget upon the actual item pickup, not every second.

What is the best approach to refresh / rebuild widget’s event construct through my CollectableBP?

Thanks!

Most of the time the answer on this question is: Event Dispatcher. To be honest, I’ve never used it until now, but as far as I can tell, it’s like the Widget is listening for events - triggered by the CollectableBP.

I think it’s well explained here:

1 Like

While I was researching on how to solve my problem, I’ve stumbled upon event dispatchers but I was unable to find a “normal” and beginner friendly tutorial on YouTube. I’ll definitely check this link out.

Thanks!

To clarify, is this how it’s supposed to work:

  • the player creates the hud widget
  • the player runs into a pickup actor
  • the hud widget gets updated

How close am I?

Anything else we need to know about? As in, the pickup actors are spawned dynamically as we progress through the game? Or there’s a limited amount placed in the level manually?


Atm, the widget is pulling the data from the player on Tick, correct?

  1. Player HUD + widget are loaded on startup
  2. Collectables are dynamically spawned across the level (“CollectableBP”)
  3. Upon a pickup → pickup values are stored (as booleans / integers) inside ThirdPersonCharacter blueprint → actor is destroyed (inside “CollectableBP”)
  4. “CollectablesIndicator” widget blueprint handles the logic and updates the display

My goal is to connect steps 3 and 4.

CURRENTLY - the widget is using EVENT TICK which constantly checks for booleans / integers values and updates the display via text transform.

IDEALLY - “CollectableBP” would “ping” the widget after destroying the actor so that the widget could recalculate and refresh the display via text transform.

I want to avoid using event tick if I can.

But which blueprints creates this widget? The player? While you absolutely can use a dispatcher for this, there may be no need.

Player runs into the pickup and updates its own hud widget. Basic direct comms would be more than enough here.

If the widget is created by the Game Mode for example, and thus is unrelated to the player blueprint, a dispatcher will be a better solution.

What you call Ideally may not be that perfect. Generally speaking, it’s the player that should handle the counting and the widget should be displaying what the player has counted. The fewer elements there are in the widget, the better.

Lemme demo something crude real quick.

1 Like

The stuff:

The player picking stuff up:

In this case, the player creates the widget and shows it. When the player runs into a collectible, we count it and set the widget’s text to that value. Here the widget was updated 4 times.

1 Like

Player_HUD (HUD) creates the collectables widget and ads it to the viewport upon event begin play.

So what is Player_HUD - another widget? The HUD class? Just trying to wrap my mind around it. The player HUD widget creates another widget - the Collectible widget?

It is HUD class.

I have tried creating the widget and adding it to the viewport from the CollectableBP after actor destroy event and it worked but it loaded one widget over another instead of updating it.

  • the HUD class creates the collectible widget:

  • the player runs into a collectible actor, gets access the HUD class and updates the widget

The above can be made better by having a custom event in the HUD and calling that.

1 Like

If you’d like to see an example taking advantage of an Event Dispatcher handling it, do tell. What spawns the collectibles?


If you wish the player knew nothing about the collectibles and prefer they talked directly to the HUD’s widget when they’re picked up, it can be arranged, too. Not a bad approach for a game where there are multiple characters.

1 Like

Wow! This example is amazing! I’ll definitely try the Cast to Player_HUD (with widget/text-block) approach! Thanks!

As for event dispatcher, it would be amazing to see how that works as well. I’d like to learn about Unreal as much as I can, so I always find interest in different approaches. :slight_smile:

Collectables are spawned through SpawnerBP - it is manually placed on multiple locations across the level and it has a chance to spawn multiple collectable types or to spawn nothing.

The idea behind Dispatchers is that one actor calls it and another actor receives that call. It makes it somewhat easier if you think about it as broadcasting and listening. Actors broadcast (call dispatchers) and other actors can listen to those calls. Actors that don’t listen cannot react to those calls.

In this instance the HUD class will listen to the Collectible actors’ calls.

Interestingly enough, actors already come with a bunch of dispatchers. You can add your own custom ones, but it’s not necessary here. Since the collectibles are getting Destroyed, we’ll use that.

IDEALLY - “CollectableBP” would “ping” the widget after destroying the actor so that the widget could recalculate and refresh the display via text transform.

The HUD class:

  • (top) create the widget and set it up

  • (bottom) A Custom Event with an Actor input - the input is required here as matching signatures on Dispatchers is a thing. When this event is called, it will update the text in the widget. Think of this element as the listening bit - it will listen to the collectible actors getting Destroyed.

The collectible actor:

  • (top) at Begin Play, aCollectibleBP registers its own (self) dispatcher call (Bind Event to On Destroyed) with the Custom Event in the HUD (pic 1).
  • Actors already broadcast their own destruction, but hardly anyone listens :(. Now the HUD will be notified when it happens and that

  • (bottom) when the collectible detects the player, it Destroys itself.

In short, collectibles getting destroyed call a custom event in the HUD.


There is no script in the player blueprint. Technically, the player does not even know about it.

2 Likes

@Everynone Thanks for that neat example! The time will come where I’ve to use a Dispatcher myself :sunglasses:

Amazing! Thanks!

I’ll give both approaches a go and fork my project.

I’ve successfully implemented your first solution. :slight_smile: No more event tick. Well, no more widget blueprint. :slight_smile:

Thanks!

I’ll try the dispatcher tomorrow as well.

1 Like