Unreal 5 Tutorial - Event Delegates

Tags
Owner
Justin Nearing

Event Dispatchers

Unreal Actor Blueprints have a feature called Event Dispatchers:

image

An Event Dispatcher, as the name suggests, sends events.

Events can be consumed by other Actors- each event acting like a trigger for a wide variety of other actor objects.

The example provided by the official documentation uses the scenario of where a final boss dies, opening a door and triggering an explosion:

For the purposes of this document, Event Dispatches have two main functions we care about:

  • Other actors subscribing to the “final boss” event, which Unreal uses theBind keyword.
  • The dispatcher actor triggering the event, which Unreal uses the Call keyword.
When the player character (called BP_ThirdPersonCharacter) collides with this actor (Event ActorBeginOverlap), trigger an event (Call On Player Triggered Platform)
When the player character (called BP_ThirdPersonCharacter) collides with this actor (Event ActorBeginOverlap), trigger an event (Call On Player Triggered Platform)
When the actor is created (Event Begin Play) subscribe the above event (Bind Event to On Player Triggered Platform)
When the actor is created (Event Begin Play) subscribe the above event (Bind Event to On Player Triggered Platform)

Bind = subscribe to event, Call = trigger event. Easy.

On the Bind node above, notice it needs a target.

The target is the Actor that owns the “On Player Triggered Event”

We need an “object reference” to that actor for this blueprint to know that the On Player Triggered Event exists.

I added the event actor as a blueprint component of my downstream actor.
I added the event actor as a blueprint component of my downstream actor.

Event Delegates

Where in blueprints you have Dispatches, in C++ you have Delegates.

#pragma once

#include "CoreMinimal.h"
#include "UObject/Object.h"
#include "AudioPlatform.generated.h"

DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FAudioPlatformTriggerDelegate, FLetsGoMusicNotes, Note);

/**
 * A small platform that triggers a musical note when stepped on
 */
UCLASS(ClassGroup=(Custom), meta=(BlueprintSpawnableComponent))
class LETSGO_API UAudioPlatform : public UActorComponent
{
	GENERATED_BODY()

public:
	UAudioPlatform();
	
	UPROPERTY(BlueprintCallable, BlueprintAssignable, Category = "MyGame | AudioPlatform")
	FAudioPlatformTriggerDelegate OnAudioPlatformTriggerDelegate;

};

DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam declares a