Search Unity

Optimization and Live Mode

Discussion in 'Multiplayer' started by TheDreamEXE, Feb 22, 2018.

  1. TheDreamEXE

    TheDreamEXE

    Joined:
    May 14, 2015
    Posts:
    60
    Hey everyone. I have done a lot of digging through the forums and as I get ready to launch my game, I have a couple of major questions that are still unanswered and hopefully they'll be cleared up.

    First question is in regards to network optimization. I have a 1v1 action game that on occasion experiences either moderate to severe lag, and/or disconnects. As far as disconnects go, I think it has to do with the 4kb limit. Theoretically this could be fixed in live mode with some tweaking, although I wish there was an easier way to determine the cause. As far as lag is concerned, I'm referring to actual inputs and commands being received, NOT movement stuttering. I've tried playing with some QoS channels in the Network Manager as well as timeouts, but I simply do not understand when to use what channel and what numbers are optimal to plug in.

    In regards to live mode, is there a clear way to determine the average size of a network message? And also are there general tips to compress the amount of messages sent or even some helpful tips to get the lowest necessary data sent across the network with the minimal amount of latency? I know, the dream scenario. Thanks in advance for any and all input. This stuff has been driving me crazy with anxiety haha
     
  2. Ellernate

    Ellernate

    Joined:
    Aug 25, 2017
    Posts:
    81
    4kbps is really low but should be doable in a 1v1 game, granted you aren't syncing tons of objects. There are countless ways to save bandwidth and it really depends on what kind of game you are going for. Anyways, here are some general bandwidth-saving tips:

    1) Reduce how often you send data. The biggest one would be if you are using Network Transform, experiment with decreasing the send rate until you reach the minimum value it where feels playable. For scripts, you can decrease the send interval for sync vars and rpcs/commands: https://docs.unity3d.com/ScriptReference/Networking.NetworkSettingsAttribute.html

    2) Simulate as much as possible on the client. Again, it really depends on the type of game and what you are trying to accomplish. Only send data that you need to.

    3) Combine messages. For example, if you are syncing multiple inputs such as vertical, horizontal, crouching, sprinting -- rather than have 4 separate syncvars or commands, you can combine them all into one struct and sync that instead. This should only be done for things that are updated at the same time.
     
  3. TheDreamEXE

    TheDreamEXE

    Joined:
    May 14, 2015
    Posts:
    60
    Interesting. Thanks for the advice! I had no idea about changing interval rates in particular. That'll be something to mess with. I've done a lot of the other stuff which has lowered my bandwidth usage to about 30% of where it was before posting this. One major issue is still lag when a player (namely the non-host client) inputs a button whereas my older builds that hogged bandwidth did not have this issue. I'm wondering if it's potentially due to how I rewrote the code.

    One other question is how do QoS channels affect performance? I flat out just do not understand. I mean, I get the concept that the various channels have benefits that can be isolated for different Commands/RPCs, etc to have a more efficient travel, but is there a best practice? I just want the game to run as smooth as possible with minimal packet loss. I've also played with some of the time out settings and I'll try to get a screenshot tomorrow if I can
     
  4. Ellernate

    Ellernate

    Joined:
    Aug 25, 2017
    Posts:
    81
    In most cases you will only need to be using the unordered reliable and unreliable channels. Unreliable should be used for things that are regularly updated and won't have any major effects if a packet is lost -- an example is position updates for a player. Reliable would be for important things that can't be missed such as inputs.

    Also I recommend reading up on this from other gamedev places. Networking is important to learn and there are many detailed explanations out there
     
    TheDreamEXE likes this.
  5. Deleted User

    Deleted User

    Guest

    Inputs should be sent by unreliable channel also.