Multi-cast delegates are a great way to broadcast an event to multiple objects who listen or subscribe to the event in question. They are particularly invaluable if you have a C++ module that generates events that potentially arbitrary Actors might want to be notified about. This recipe shows you how to create a multi-cast delegate in C++ that can notify a group of other Actors during runtime.
Create a new
StaticMeshActor
class calledKing
. Add the following to the class header:DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FOnKingDeathSignature, AKing*, DeadKing);
Add a new
UFUNCTION
to the class:UFUNCTION(BlueprintCallable, Category = King) void Die();
Add an instance of our multicast delegate to the class:
UPROPERTY(BlueprintAssignable) FOnKingDeathSignature OnKingDeath;
Add our mesh initialization to the constructor:
auto MeshAsset = ConstructorHelpers::FObjectFinder<UStaticMesh>(TEXT("StaticMesh'/Engine/BasicShapes/Cone.Cone'"));...