Custom delegates are quite useful, but one of their limitations is that they can be broadcast externally by some other third-party class, that is, their Execute/Broadcast methods are publically accessible.
At times, you may want a delegate that is externally assignable by other classes, but can only be broadcast by the class which contains them. This is the primary purpose of Events.
Make sure you've followed the initial recipe in this chapter so that you have the MyTriggerVolume
and CookBookGameMode
implementations.
Add the following event declaration macro to the header of your
MyTriggerVolume
class:DECLARE_EVENT(AMyTriggerVolume, FPlayerEntered)
Add an instance of the declared event signature to the class:
FPlayerEnteredOnPlayerEntered;
In
AMyTriggerVolume::NotifyActorBeginOverlap
, add this:OnPlayerEntered.Broadcast();
Create a new
Actor
class, calledTriggerVolEventListener
.Add the following class members to its declaration:
UPROPERTY() UPointLightComponent...