Search Unity

Resolved NetCode for gameobjects : how to get delay between server and client?

Discussion in 'Netcode for GameObjects' started by PersianKiller, Jan 11, 2023.

  1. PersianKiller

    PersianKiller

    Joined:
    Jul 16, 2017
    Posts:
    132
    Now I'm sending clock time form server to client, the difference is small but I want to know the time that took the server to send the message to client then add it to the client clock time to get the server time, how Can I do this?

    1. NM.NetworkConfig.NetworkTransport.GetCurrentRtt(0);
    it didnt help
     
  2. Evil-Otaku

    Evil-Otaku

    Joined:
    Oct 17, 2012
    Posts:
    72
    PersianKiller likes this.
  3. neviovalsa

    neviovalsa

    Joined:
    Jun 24, 2019
    Posts:
    52
    ServerTime doesn't seem to be properly synched.
    I ended up doing combining it with half the roundtrip time to get a better estimate of the actual server time from a client, like so:
    Code (CSharp):
    1. float EstimatedActualServerTime = ((NetworkManager.Singleton.NetworkConfig.NetworkTransport.GetCurrentRtt(NetworkManager.ServerClientId) / 2000) + NetworkManager.Singleton.ServerTime.TimeAsFloat);
    I actually just opened another thread on the topic wondering if what I'm doing is best practice.
     
    PersianKiller likes this.