Search Unity

Bandwidth - ClientRpc, Command, SyncVar

Discussion in 'Multiplayer' started by Tyrfingur, Oct 30, 2015.

  1. Tyrfingur

    Tyrfingur

    Joined:
    Mar 21, 2013
    Posts:
    7
    Hey guys!
    I would like to know the bandwidth for each call/sync of :

    ClientRpc - with and without variables
    Command - with and without variables
    SyncVar - for each variable

    I'd guess the bandwidth for each variable should be its size (int = 32 bits, Vector3 = 3x32 bits etc.).
    Should I be optimizing each int/float to a smaller value (short/byte/sbyte) if possible?
    I read somewhere, can't find the link, that the int size was scaling from 8-32 bits depending on the value, is that correct?
     
  2. snacktime

    snacktime

    Joined:
    Apr 15, 2013
    Posts:
    3,356
    Your biggest win is looking at everything you send, and asking if you really need to be sending it. Next is tricks to optimize that. Last is bit packing and low level optimization involving data structures.


    Most people just throw transforms around like they are candy. Do you really need to be sending that quaternion? Most times the answer is no. Do you really need to be sending a vector3? Again usually not. Just stop assuming everything about what you need to send and rethink the problem. What is it you are really trying to accomplish? You want the player to rotate? What makes you think you need a whole transform? Why not just send an angle on one axis?

    For vectors do you really need to send Y if you are on terrain?

    Stuff like that trumps low level data structure optimization in spades. Once you get that then start looking at bit packing and delta's. Delta's as in just sending what's changed. Why send a whole vector3 when something only moved 0.01?
     
  3. Tyrfingur

    Tyrfingur

    Joined:
    Mar 21, 2013
    Posts:
    7
    Thanks for the answer snacktime :)
    The main things I'm sending/syncing are position(vector2) and input(vector2). And the main reason for my question is that I saw a big difference between my levels - one level where players score alot (clientRpc) and another level were they score once in a while.
    So, if the clientrpc calls cost alot of bandwidth I'd have to rethink some of my code.