Skip to main content

Shared time and ticks

Every player in a room shares one clock.

API
Networking.GetServerTimeInSeconds()Room time in seconds (double), the same for everyone
Networking.GetServerTimeInMilliseconds()The same in milliseconds (int, wraps around)
Networking.GetServerTick()The room's network tick. A tick number is the same moment for everyone
Networking.GetTickRate()Network ticks per second

Time.time and Time.deltaTime are local to each player: use them for smooth local motion, and the room clock for anything that must line up between players.

Moving in step without sending data​

Rather than syncing something that changes every frame, sync when it started and let every player work out the rest from the shared clock. Nothing is sent while the cube spins, and late joiners are in step immediately.

public class TickRotatingCube : StageTimeBehaviour
{
public float degreesPerSecond = 90f;

[Synced] private bool spinning = true;
[Synced] private float baseAngle; // angle when it last started or stopped
[Synced] private int startTick; // network tick when it last started or stopped

private void Update()
{
transform.localRotation = Quaternion.Euler(0f, CurrentAngle(), 0f);
}

public override void Interact()
{
Networking.SetOwner(Networking.LocalPlayer, gameObject);
baseAngle = CurrentAngle(); // freeze or resume from where it is now
startTick = Networking.GetServerTick();
spinning = !spinning;
}

private float CurrentAngle()
{
if (!spinning) return baseAngle;
double elapsed = Networking.GetServerTimeInSeconds() - (double)startTick / Networking.GetTickRate();
return (float)((baseAngle + elapsed * degreesPerSecond) % 360.0);
}
}

The same pattern works for timers, rounds, moving platforms and music that must stay in sync. The full version with a live label is in the Tick-synced cube example.