Updating Time Zone with Blueprint - jgoffeney/Cesium4Unreal GitHub Wiki

Back

Description

The CesiumSunSky is mainly accessible as a blueprint class and this describes how to update the time zone based on the longitude position of the camera. It relies on using Unreal events and delegates.

Cpp

In the MainActor C++ class define the macro and declare the event.

Macro

Declare a one parameter delegate named FOnTimeZoneUpdate with an integer variable named timeZone.

DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FOnTimeZoneUpdate, int, timeZone);

Event

Declare the event for the delegate FOnTimeZoneUpdate.

UPROPERTY(BlueprintCallable, BlueprintAssignable, Category = "Event Dispatchers")
    FOnTimeZoneUpdate OnTimeZoneChanged;

Broadcast

During the Tick function the time zone is computed from the Longitude value and if is different than the previous value the new value is broadcast out.

OnTimeZoneChanged.Broadcast(timeZone);

Blueprint

This blueprint shows the binding of the delegate function OnTimeZoneChanged and updates the CesiumSunSky instance time zone.

  • From the MainActor class object create a blueprint object as MainActor_BP and add it to the scene.
  • Make the CesiumSunSky accessible to the MainActor_BP.
    • Open the MainActor blueprint and under MyBlueprint->Variables add a new variable called SunSky of type Cesium Sun Sky and click the eye open to make it public.
    • Go back to the main editor and select the MainActor_BP. Under Details->Default->Sun Sky and set the CesiumSunSky instance for its value.
  • Create the time zone update graph
    • Back in the blueprint from the Event BeginPlay create a _Bind Event On Time Zone Changed _ node and from its Event input create a Custom Event.
    • Create a Get Sun Sky node by right clicking on the graph.
      • From the SunSky output create a Set Time Zone node and connect the Custom Event exec and Time Zone pins.
      • Also from the SunSky output create an UpdateSun node and connect its input exec pin to the output pin of the Set Time Zone node. Calling UpdateSun is required to change the position of the sun.

UpdateSunSkyTimeZone