The standard delegates used so far in this chapter are essentially a function pointer—they allow you to call one particular function on one particular object instance. Multicast delegates are a collection of function pointers, each potentially on different objects, that will all be invoked when the delegate is broadcast.
This recipe assumes you have followed the initial recipe in the chapter, as it shows you how to create TriggerVolume
that is used to broadcast the multicast delegate.
Add a new delegate declaration to the
GameMode
header:DECLARE_MULTICAST_DELEGATE(FMulticastDelegateSignature)
Create a new
Actor
class calledMulticastDelegateListener
. Add the following to the declaration:UFUNCTION() void ToggleLight(); UFUNCTION() virtual void EndPlay(constEEndPlayReason::Type EndPlayReason) override; UPROPERTY() UPointLightComponent* PointLight; FDelegateHandleMyDelegateHandle;
In the class implementation, add this to the constructor...