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.