Delegates allow us to call a function without knowing which function is assigned. They are a safer version of a raw function pointer. This recipe shows you how to associate a UFUNCTION
to a delegate so that it is called when the delegate is executed.
Inside our
GameMode
header, declare the delegate with the following macro, just before the class declaration:DECLARE_DELEGATE(FStandardDelegateSignature) UCLASS() class UE4COOKBOOK_API AUE4CookbookGameMode : public AGameMode
Add a new member to our game mode:
FStandardDelegateSignature MyStandardDelegate;
Create a new
Actor
class calledDelegateListener
. Add the following to the declaration of that class:UFUNCTION() void EnableLight(); UPROPERTY() UPointLightComponent* PointLight;
In the class implementation, add this to the constructor:
PointLight = CreateDefaultSubobject<UPointLightComponent...