Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Networking behaves weirdly or stops working at all when timeScale is set to 0

Discussion in 'Multiplayer' started by Lohoris2, Dec 11, 2016.

  1. Lohoris2

    Lohoris2

    Joined:
    Aug 20, 2013
    Posts:
    85
    (Unity 5.4.1)

    I'm experiencing odd behaviours trying to set the timeScale to 0.

    If I set it to 0 on the server and not on the clients, it sort-of works, but the clients keep interpolating the NetworkTransform positions as if they were lagging: I think this means that the server isn't telling them "this object is still", it means it just stopped telling them anything at all, which is bad.

    If I set the timeScale to 0 on both the server and the clients, the clients stop working. Like, at all. They suddenly behave weirdly, as if setting the timeScale to 0 also partly blocked their network capabilities and they don't know what to do. I'm not exactly sure how to describe it, but despite the timeScale of server and clients should be synced, it's as if they weren't, so that the clients basically never get the chance to act.

    I guess this should be simply reproductable with a simple project were the server sets his own timescale to 0 and sends a ClientRpc telling the clients to set their to 0 too, after a while resume setting server's timescale to 1 and send another ClientRpc telling the clients to do the same… and this won't happen.

    So, basically, I'm under the impression that timeScale also somehow affects networking, when I think it really should not… is that intentional? If not intentional, is this a known behaviour? If intentional… why?
     
  2. thegreatzebadiah

    thegreatzebadiah

    Joined:
    Nov 22, 2012
    Posts:
    836
    Check it out: https://bitbucket.org/Unity-Technol...nsform.cs?at=5.4&fileviewer=file-view-default

    NetworkTransform specifically uses Time.time which in my opinion couldn't possibly make any sense. The solution seems to be "don't use NetworkTransform" or "don't mess with time scale."

    There are also some other references to Time.time that may be harmless but there's one in NetworkBehaviour.GetDirtyChannel() that very well could effect syncing.

    Just another "feature" of UNet.

    Frankly even without the Time.time issue I wouldn't recommend anyone use NetworkTransform for anything but testing anyway. It's pretty trash on a number of different levels.
     
    Lohoris2 likes this.
  3. Mikael-H

    Mikael-H

    Joined:
    Apr 26, 2013
    Posts:
    309
    Does your "Smooth Sync" asset deal with this in a more elegant way? So that it is possible to pause a game through cmd/rpc and not have the transform go bananas when you resume?

    I see that you released it a long time after writing this post, I bet you got fed up at last :D
     
  4. RecklessGames_

    RecklessGames_

    Joined:
    Jul 30, 2010
    Posts:
    222
    I believe this issue is still persistant. If I change Time.timeScale = 0 on the Server it will stop sending information to the clients of its position data.(SyncVar using [Command]) But if i Change time on client it has no issues. I'm currently looking for a way to do a manual position update to get around this issue.

    p.s. someone said they got theres working by keeping the TimeScale on the Server at 1. but not sure how I would go about implementing my own Slow effects on everything in the World. Physics etc.
     
  5. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    580
    @Mikael-H
    Hi, I'm not the great Zeb but we definitely got fed up with NetworkTransform, haha.

    I just tested pausing and unpausing from cmd/rpc in Smooth Sync and I couldn't see any problems at all. Thanks for the feature list idea, I forgot games would want to do that. :)
     
  6. Mikael-H

    Mikael-H

    Joined:
    Apr 26, 2013
    Posts:
    309
    Thank you for the answer. I couldn't wait so I just bought the asset and tried it out. I must say it was very simple to use! I really like how I can just replace the NetworkTransform and have everything working exactly the same from a developer point of view with all the magic happening in the background. Nice work!
     
    Fuestrine likes this.