RPC Parameter Optimization

Hey everyone, I am building a multiplayer RTS style game which needs to keep hundreds of characters up to date over the network. I use RPC calls for everything so I can be very selective about what needs to be updated. Things are working pretty well so far, but I have a few questions about optimizing RPC calls.

I know Unity is very smart, and I was wondering if it does anything behind the scenes to compress int values? For example, I have a bunch of values which I know will never exceed 10. So I do something like...

void ReplicateAllValues( int valueA, int valueB, int valueC )
  int valueSentWithRPC = valueA + valueB*10 + valueC*100 ;
  networkView.RPC("ReceiveAllValues", RPCMode.All, valueSentWithRPC );
void ReceiveAllValues( int valueFromRPC )
  int valueA = valueSentWithRPC % 10 ;
  int valueB = (valueSentWithRPC % 100) /10 ;
  int valueC = (valueSentWithRPC % 1000) /100;

Is this worth my time? Or does Unity do compression behind the scenes that makes this silly?

Secondly, how much bandwidth overhead is there for each RPC call? If I make 100 calls to a function which takes a single int, how much worse is that than calling a single function which takes 100 parameters?

Finally, am I correct in thinking that if I do not declare a NetworkMessageInfo parameter in my [RPC] function that bandwidth will be saved? Or is that information always sent reguardless?


Hi, this is a really old question but thought I’d give it a shot.

You can send byte arrays, which is a really good optimization in your case where you know that the values never exceed 10, so you can call one rpc with one byte array[100].

if you really want to optimize your bandwidth, you can split the byte in 2. So you have to 4 bits that can represent 0-15. This can also be done with a int splitting it to 8 4 bits if you often have bigger updates and want to minimize bandwidth, of course this comes at a minor processor cost.