Search Unity

Delay in synchronization in unity3d Unet

Discussion in 'UNet' started by IMAN_SH, Jan 25, 2019.

  1. IMAN_SH

    IMAN_SH

    Joined:
    Mar 8, 2016
    Posts:
    16
    I'm working on an online multiplayer fps game with unity3d UNET HLAPI but i have sireus problem recently.

    First of all, I must say that everything is fine. and I use commands , syncvars and sometimes rpc to sending data between clients and server. and my unity's version is 2018.

    I run my servers in dedicated windows server by running EXE files. And players can play without any serious problems.

    But after some time in sending data between players and the server occurs a delay.

    For example when player one kill Player two , player one send a command to server that i killed player two and server do update syncvars by reducing health. But after a while in this type of synchronization (commands, syncvars, rpcs), the delay lasts a few seconds. (3 second, 4 or 5 second delay). Or when a client decide to walking , His walk is displayed to others by delay.

    I add that I recently set the frame rate to 60 on my servers. Can there be anything to do with this problem?

    I want to know if anyone has such an experience? Is there a way to prevent this problem?
     
  2. TheLastVertex

    TheLastVertex

    Joined:
    Sep 30, 2015
    Posts:
    126
    I would highly recommend these two wonderful articles if you haven't read them yet, they might give you some ideas or mention something you haven't considered before: Gabriel Gambetta and Gaffer On Games.

    With that said this is hard to nail down from an outside perspective. If the delay is getting greater the longer the match is running I would start to look at both the sender of the data that is being delayed and the receiver of the data that is being delayed.

    Obvious example: If the server is sending 60 updates a second but the client can only process 30 in the same amount of time. The client will always get farther and farther behind. This would happen if there are frame rate differences between client and server, and if they are not frame rate independent. If the server is sending 60 updates a second but the clients potato of a PC can only run at a max of 30 frames a second you need to make sure you have a way to handle this.

    Subtle Example: If there is latency changes even though extremely minor and unnoticeable these can compound. If for say the clients network spikes and it doesn't receive any updates from the server for 100ms. When the client starts receiving data again they are going to get the previously sent updates from the server that are arriving late, all the new updates that are arriving on time, and they have lost out on a potential 100ms of processing time. Depending on how these are managed you could end up with a growing queue of data to process. If this happens over and over and over again with no way to catch up the client is going to get farther and farther behind. You need a way to handle this.

    Time is a killer: Look anywhere you are using anything related to Time. Similar to the above if you are passing time values to something or sending time values across the network. Double check how this is being processed, how its accounting for time differences between client and server and how it's impacted by latency.

    Hope this is helpful, good luck!
     
    Last edited: Jan 27, 2019
    IMAN_SH likes this.