optimization of bandwidth consumption is an essential issue for multiplayer games.
Unfortunately, I have not found a documentation of the bandwidth consumptions / overheads of UNET HLAPI features such as ClientRPC, Command and SyncVar.
Especially in order to create a decent network architecture design, I would like to know how much bandwidth is basically consumed by these functions at bare bones (e.g. header data only, without the actual data). This information seems to be crucial in order to implement proper designs and bandwidth optimizations.
For example, if I send a ClientRPC with just a single byte, how much bandwidth does it actually consume in total?
Same question for SyncVar and Command.
Well I can not say it for sure how much is added but at least for ClientRPC and Command there is an additional NetworkHash128 (128 bits) for the name of the method in question.
If I remember correctly, the hash is used to identify the function and is unique across the entire build. If you used a single byte you would be limited to ~256 clientRPC/Commands across the build or would need to track hashes in a more possibly unreliable way. The hash is stored in a static dictionary on NetworkBehaviour or NetworkIdentity with the class type and function associated with it.
The packet payload for a RPC message is 2 bytes for size, 2 bytes for RPC message type, packed 1-5 bytes for hash, packed 1-5 bytes for netid plus any arguments passed to RPC function.
SyncVar message: 2 bytes size, 2 bytes SyncVar type(8), packed 1-5 bytes netid, plus (either all syncvars or dirty syncvars + packed 1-5 bytes for dirty bits) for each dirty NetworkBehaviour. A SyncVar message is set for each dirty channel for each NetworkIdentity.
It uses the SyncVar message, It seems to sync all values when dirty bit is set, rotation and spin axis will be compressed based on Compression Value. Rotation and Spin axis will only be sent if Axis Sync is set.
For SyncTransform arguments are: 12 bytes position, 0-3 rotation angles based on axis sync * (2 or 4 bytes based on compression)
For Sync2D arguments are: 8 bytes position, 8 bytes velocity, (2 or 4 bytes) if axis sync, (2 or 4 bytes) if sync spin
For Sync3D arguments are: 12 bytes position, 12 bytes velocity, 0-3 rotation angles based on axis sync * (2 or 4 bytes based on compression), 0-3 spin angles based on axis sync and sync spin * (2 or 4 bytes based on compression)
For SyncCharacterController arguments are: 12 bytes position, 0-3 rotation angles based on axis sync * (2 or 4 bytes based on compression)
Actually there are more reliable ways to compress hash values and recurring strings like Huffman coding but i’m not sure if it is worthwhile here or not.