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:
    FOnTimeChangedSignatureOnTimeChanged;
  4. Add the following properties to the class:
    UPROPERTY()
    int32 TimeScale;
    
    UPROPERTY()
    int32 Hours;
    UPROPERTY()
    int32 Minutes;
    
    UPROPERTY()
    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.