Unity-Technologies / com.unity.netcode.gameobjects

Netcode for GameObjects is a high-level netcode SDK that provides networking capabilities to GameObject/MonoBehaviour workflows within Unity and sits on top of underlying transport layer.
MIT License
2.15k stars 435 forks source link

fix: Sync local time with server more accurately #3028

Open BenHamrick opened 3 months ago

BenHamrick commented 3 months ago

When syncing the local time from the server to the client we need to use half the RTT time to get the local time in sync with the server. Otherwise the local time drifts relative to how long the RTT time is.

Changelog

Testing and Documentation

unity-cla-assistant commented 3 months ago

CLA assistant check
All committers have signed the CLA.

NoelStephensUnity commented 3 months ago

@BenHamrick That does indeed look like it makes sense... half RTT vs 1 full RTT for the delta time adjustment. Running some tests against this, but so far it looks like that would be a welcome contribution. 👍

BenHamrick commented 3 months ago

@NoelStephensUnity I am really glad to hear that! We are using the tick in our own custom physics engine to do predictive rollback on the server and client. I have been so confused for a long time about why the tick is not in sync between the client and the server. We even started to write our own syncing system that worked around this problem like people are in this thread: https://discussions.unity.com/t/network-messaging-latencies-very-high/912504/2 . I probably spent more than 40 hours trying to work around the issue by dynamically changing the NetworkManager.NetworkTimeSystem.LocalBufferSec

Btw to figure this problem out I used the relay server with 2 instances of unity running on the same machine. Then I was able to use local epoch time to see if each of the ticks are in sync between the server and client. They where not!

BenHamrick commented 2 months ago

@NoelStephensUnity how long does it take to merge and backport a simple change like this?