This entity is UNUSED because of Ultimate Dynamic Sky plugin introduced to the project. It has itself replication between clients and comes with out of the box real-world time replication and necessary functions and properties.
ARealworldTimeSync Class Documentation
Inheritance:AActor
→ ARealworldTimeSync
Overview
ARealworldTimeSync
is an actor designed to synchronize real-world time to the game. Can be used to set some events based only on real time.
Time is gathered from server or listen-server. (Hosting player)
Key Features
Real-World Time Synchronization:
Updates a replicated time variable that reflects server’s real-world time.Flexible Refresh Rate:
The frequency of updates can be customized viaSyncRefreshTime
, controlling how often real-world time is synced to clients.Blueprint Integration:
Includes BlueprintCallable and BlueprintAssignable functions and events.
Properties
Time Synchronization
SyncTime (
bool
, ReplicatedUsing=OnRep_SyncTimeToggle
)
Determines if the actor should actively sync the in-game time-of-day with the server’s real-world time.- Tooltip: “That makes time of day system in the map to be synced with the server real time world clock”
- Default: true
RealWorldTime (
int32
, ReplicatedUsing=OnRep_TimeChanged
)
An integer representing the server’s current real-world time.- Note: The exact meaning/format of this time (e.g., seconds since midnight, UTC timestamp) can be defined by game logic.
- Triggers
OnRep_TimeChanged
when updated.
SyncRefreshTime (
int32
, EditInstanceOnly)
The frequency (in seconds) at which the actor will attempt to re-sync the real world time with the server.- Default: 60 seconds
Delegates and Events
- OnTimeChanged (
FOnTimeChanged
)
A multicast delegate called when theRealWorldTime
changes, allowing listeners (e.g., UI Widgets, time-of-day managers) to react and update accordingly.
Signature:void OnTimeChanged(int32 CurrentTime)
Public Methods
SyncNow() (
UFUNCTION(BlueprintCallable)
)
Forces an immediate synchronization of theRealWorldTime
with the server’s current real time.GetRealWorldTime() (
UFUNCTION(BlueprintGetter)
)
Returns the current value ofRealWorldTime
. This can be used to retrieve the last synchronized real-world time on the client side.
Replication and Networking
OnRep_TimeChanged() (
UFUNCTION
)
Called on clients wheneverRealWorldTime
is updated. TriggersOnTimeChanged
delegate, allowing client-side logic to respond immediately.OnRep_SyncTimeToggle() (
UFUNCTION
)
Called on clients wheneverSyncTime
is toggled. Could be used to enable/disable client-side logic that depends on ongoing synchronization.
Event Flow
Server Initialization:
UponBeginPlay()
, the server initializes the actor and setsNextSync
to schedule the first synchronization.Periodic Syncing (Server-side):
InTick(DeltaTime)
, if the current time exceedsNextSync
andSyncTime
is true, the server updatesRealWorldTime
to reflect the current real timeClient Updates:
WhenRealWorldTime
orSyncTime
changes, replication notifies clients viaOnRep_TimeChanged()
andOnRep_SyncTimeToggle()
. Clients can then adjust their UI or time-of-day representations accordingly.Manual Sync:
If theSyncNow()
function is called (from server or client if the client has permission), the server updatesRealWorldTime
immediately and broadcasts the change to all clients.
Usage Example
Placement and Configuration:
PlaceARealworldTimeSync
in the level. SetSyncRefreshTime
to the desired frequency (e.g., every 60 seconds). EnsureSyncTime
is true if real-world syncing is desired.Listening for Changes (Blueprint):
In a Blueprint that manages the day/night cycle or displays the current time, bind toOnTimeChanged
. When triggered, readGetRealWorldTime()
to adjust the in-game clock accordingly.Forcing an Update:
At any time, callSyncNow()
to request an immediate time sync. This can be useful before scheduled in-game events, ensuring times are up-to-date.
This actor ensures that all players experience a game world closely tied to real-world timing, enhancing immersion and enabling real-time events or persistent world mechanics.