Creating a delegate that is bound to a UFUNCTION
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.
Getting ready
Ensure you've followed the previous recipe in order to create a TriggerVolume
class.
How to do it...
- 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 ...
Get Unreal Engine 4 Scripting with C++ Cookbook now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.