Creating a Time of Day handler

This recipe shows you how to use the concepts introduced in the previous recipes to create an actor that informs other actors of the passage of time within your game.

How to do it...

  1. Create a new Actor class called TimeOfDayHandler.
  2. Add a multicast delegate declaration to the header:
    DECLARE_MULTICAST_DELEGATE_TwoParams(FOnTimeChangedSignature, int32, int32)
  3. Add an instance of our delegate to the class declaration:
  4. Add the following properties to the class:
    int32 TimeScale;
    int32 Hours;
    int32 Minutes;
    float ElapsedSeconds;
  5. Add the initialization of these properties to the constructor:
    TimeScale = 60; Hours = 0; Minutes = 0; ElapsedSeconds ...

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.