AGameStateBase::GetServerWorldTimeSeconds
#include "GameFramework/GameStateBase.h"
Access: public
Specifiers: virtualUFUNCTIONBlueprintCallable
Description
Returns an approximation of the server's current WorldTimeSeconds, synchronized across server and clients via periodic replication. Use this instead of GetWorld()->GetTimeSeconds() when you need a time value consistent across all machines.
Caveats & Gotchas
- • The value is only as fresh as the last replication update. ServerWorldTimeSecondsUpdateFrequency (default ~5 seconds) controls how often it syncs. For sub-second precision (e.g., lag compensation), use a dedicated time-sync approach rather than relying on this.
- • On the server, this returns the actual world time plus zero delta. On clients, it returns the replicated time plus a computed delta (ServerWorldTimeSecondsDelta), which smooths over network jitter using a rolling average — sudden network hitches can cause brief inaccuracies.
- • Changed from float to double in UE 5.1 to support long-running sessions (float loses sub-second precision after ~4.5 hours). If you store the result in a float variable in older code, you'll silently lose precision — use double.
Signature
ENGINE_API virtual double GetServerWorldTimeSeconds() const; Return Type
double Example
Stamp an event with synchronized server time C++
void AMyActor::OnPickupCollected(APlayerController* Collector)
{
if (HasAuthority())
{
AGameStateBase* GS = GetWorld()->GetGameState<AGameStateBase>();
double ServerTime = GS ? GS->GetServerWorldTimeSeconds() : 0.0;
UE_LOG(LogTemp, Log, TEXT("Pickup collected at server time: %f"), ServerTime);
// Replicate this timestamp to clients for replay or UI display
}
} Tags
Version History
Introduced in: 4.14
| Version | Status | Notes |
|---|---|---|
| 5.6 | stable | — |
| 5.1 | stable | Return type changed from float to double for long-session precision. |
Feedback
Was this helpful?