Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Syncing a lot of networked objects

Discussion in 'Multiplayer' started by Doleman, Feb 1, 2008.

  1. Doleman

    Doleman

    Joined:
    Aug 12, 2005
    Posts:
    87
    Hi all,

    We have been working on a multiplayer game lately but when we have sort of come to a huge wall, namely syncing...

    * We have around 100 objects running around the board in-game
    * They are all controlled by a server, and synced via OnSerializeNetworkView.
    * We only need 3 variables per object synced. Position.x, position.y and direction. We used the NetworkInterpolatedTransform script as a base and just replaced the stuff we needed.

    Since the objects move constantly we get a lot of choppy behaviour. We move the objects at the clientside too, with Time.deltaTime and yet it becomes very choppy
    We have tried to alter the synch frequency also, with not much difference (well it got worse when we lowered it :p )

    Does anyone have any ideas regarding how to get this to work better? Anyone who've used constantly moving objects before?
     
  2. larus

    larus

    Unity Technologies

    Joined:
    Oct 12, 2007
    Posts:
    277
    That is a lot of objects and information to sync but it should not be a problem if you only have two parties in the game, a client and a server.

    Just general comments for this:

    1. You might want to look at how you are playing back the state of the objects. If the objects are predicted (i.e. run the same scripts as the server which make them move/do stuff) on the clients or remote parties then you might want to look at if they are deploying old state received from the network. In this case you need to save the state of the object in a buffer of some specific size and when a network update arrives, you don't deploy it but compare it with an older state with approximately the same timestamp. Then you are more accurately checking if the prediction was correct or incorrect with some margin. This is done in the players character in the TPS-Auth scene in the networking example project.

    2. I did a quick test scene and instantiated 100 cubes and synched them over the network. I found it synched fine as long when I used the InterpolatedNetworkTransform script and reliable diff compressed sync method, with the default send rate. You need to disable the script on the instance which does the instantiation, which is the server in your case. The first few seconds were a bit choppy right after the 100 objects were instantiated on the remote party but after that the sync was smooth. I only rotated the objects around all axes so just 3 variables (floats) were being synched, like in your situation.

    3. You might feel your way around by checking the network stats when you are running both instances, maybe comparing the timestamp of state which you are deploying on remote parties and see if its old. Compare with predicted state + timestamp. Watch the log with network debugging set to full debug. It does slow things down as it writes out a lot of stuff, but its shows what you are actually sending (is it what you want to send).
     
  3. Doleman

    Doleman

    Joined:
    Aug 12, 2005
    Posts:
    87
    Thanks a lot Larus :)

    We will look into the predicted state and compare with timestamp of the incoming packets