Search Unity

Network.time returning different values on different computers

Discussion in 'Multiplayer' started by Alabatross, Sep 12, 2014.

  1. Alabatross

    Alabatross

    Joined:
    Dec 15, 2012
    Posts:
    223
    I was under the assumption that Network.time is synced for everyone (not super precisely but close) as displaying the time in seconds since the server was started.

    When I first started debugging it this morning it started counting at about 14000 as soon as the server started... And I noticed that it continues to count up even when the server is not launched?

    I went further into debugging and comparing these, so later today I had a friend connect with about 150 ping. His Network.time was at about 2200 while mine was at 47000.

    Am I just not understanding this? What is going on
     
  2. Ashkan_gc

    Ashkan_gc

    Joined:
    Aug 12, 2009
    Posts:
    1,124
    Well unity's time synchronization algorithm is not that robust and powerful. As far as I know only hero engine and uLink are the solutions in the market which have automatic robust time synchronization.
    Synchronizing time on the network is a complex process. The number can drift away due to variable ping between client and server, floating point errors (if floats are used for time representation) and some other issues. If you want to make a game which absolutely needs this then you should implement it yourself or take a look at www.muchdifferent.com to get uLink / UnityPark suite.
    The Great time synch which is much improved and is based on algorithms which financial institutions use, is in kind of private beta yes so you should contact support@muchdifferent.com to get it.
     
  3. Alabatross

    Alabatross

    Joined:
    Dec 15, 2012
    Posts:
    223
    I synced the time fine myself pretty easily once I realized there was no way to fix the Network.time output, but thanks.
     
  4. Ashkan_gc

    Ashkan_gc

    Joined:
    Aug 12, 2009
    Posts:
    1,124
    Well actually solving this robustly is not that easy.
    If you want, you can send time with periodic RPCs with a rate of x times per minute and then after receiving the rpc you add the messages time stamp's delta to your time to it but in that case you are using network time's value and also due to the way that messages are being sent time might go backward and you should have a smooth time function which fixes it. Also your time variable should not reset after some time if the game is long running like MMOs. The other thing is that if you have lots of traffic you should not use a lot of bandwidth for it. RPCs are unfortunately forced to be reliable in Unity Network, this can become a problem if you have lots of reliable messages on the server and a bad network condition on the receiving side.

    These all can become problems for more network stressed games and if it works for you then, Great!
     
  5. Alabatross

    Alabatross

    Joined:
    Dec 15, 2012
    Posts:
    223
    I just compare the clients time with the servers every 5-10 seconds to make sure it's still correct, they both continue to count side by side with ping factored in independent from fps

    So far everything seems to be lining up perfectly
     
  6. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,066
    My 2 cents: Once you know the server's time, it might make sense to simple extrapolate it based on local time per client. If you re-sync the time in a running game, it affects how long things took so far.
    Difficult to describe. Let's say you want a game round to take a minute based on a server's start time. You begin the round and expect to have 60 seconds. Then your server time gets updated and you notice it's later on the server than you thought initially. The round will have to end earlier.