Creating Event Dispatchers in UE5 Using Blueprints
Event Dispatchers are great to communicate between components. In this example the event dispatcher updates the player's health bar.
Software Versions: Unreal Engine 5.4.4
Project Name: MyProject
Event dispatchers allow for Blueprints and other components to communicate with each other. In this example the player takes damage and then sends a message to the UI to update their health bar.
I started by creating a simple User Widget
that has a red progress bar in the top left corner.
I copied over the Third Person Template Blueprint to apply edits. In BeginPlay
we can add the new W_Health
UserWidget
to the Viewport
. In the User Widget I added a Player
variable and exposed it on Spawn
to allow the variable to be set via the character Blueprint.
On the left side of the Blueprint we can add an Event Dispatcher
, we can call it Update Health
, and that allows us to call that event dispatcher inside the character Blueprint while the User Widget
has the opportunity to subscribe to it.
In the BP_ThirdPersonCharacter_Health
Blueprint when the player takes damage we set the Player's Health
then call the Event Dispatcher
. Inside the Health User Widget
we bind to the event and update the progress bar with the new value.
To showcase the event dispatcher I created a Blueprint that can damage or the heal the player every second the player stands on the platform.
The BP_DamageHealer_Actor
will apply damage to the actor on overlap every second and then clear the timer when the player exits. I also added a Heal
boolean variable to reverse the damage for a healing platform.
I had fun creating these dispatch events. Sometimes the challenge is just getting the correct pieces in the right places, hopefully this helps.
Harrison McGuire