O'Reilly logo

Unreal Engine 4 Scripting with C++ Cookbook by Stephen Whittle, William Sherif

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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...

  1. 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
  2. Add a new member to our game mode:
    FStandardDelegateSignature MyStandardDelegate;
  3. Create a new Actor class called DelegateListener ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required