Event Dispatchers
Unreal Actor Blueprints have a feature called Event Dispatchers:
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 the
Bind
keyword. - The dispatcher actor triggering the event, which Unreal uses the
Call
keyword.
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.
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