Minimizing Network Bandwidth
It is important to think about what kind of data you are sending across the network. Ideally, you should be sending the absolute minimum amount of data to make your game work correctly on all clients.
How data is synchronized
How you decide to synchronize data affects the bandwidth you use. You have a choice of using either Unreliable or Reliable Delta Compression in each Network View.
Unreliable means everything is sent during each iteration of the network update loop. This update loop is executed according to what is set by Network.sendRate, by default 15 times per second. By using Unreliable you ensure frequent updates of information and you don't care if updates are dropped or delayed. Dropped or delayed packets are ignored. For objects which frequently change state this might be the best way of synchronizing.
Bear in mind amount of data that is constantly being sent out. For example, if you are synchronizing a transform you are sending 9 float values, 36 Bytes per update or 288 Bytes per second. For the server, if running with 8 clients, this means he receives (8*36*15) 4,320 KBytes/s or 34,6Kbits/s and has to transmit (8*7*36*15) 30,2 KBytes/s or 242Kbits/s.
You can have a dramatic effect on the bandwidth by decreasing the send rate of the network updates. This depends on you game but for fast paced game this should be quite high (like 15).
Reliable Delta Compressed means that data is sent reliably and in order, if out of order packets arrive they are held back until the correct packet is there. Data is also delta compressed which means only the difference between the last sent state and the current state is sent. If the difference is nothing then nothing is sent. This greatly decreases the bandwidth used by objects depending on how static they are during a game. A static object send no updates at all. This can however affect the latency of the state synchronization, packets might arrive delayed because they needed to be resent. In this case nothing is received at all until the dropped packet arrives. Using interpolation decreases the effect of dropped packets.
What data is synchronized
It is important to try and think creatively on how your game can be synchronized so it appears to be the same on all clients. It might not be necessary for everything to be exactly the same, a good example is synchronizing animation. When you have, for example, a character which has all sorts of animation, like walking, running, jumping etc. You want all this to appear the same but it isn't necessary to be exactly the same. If you directly put an Animation component as an observed component in a Network View then it is exactly synchronized. It sends time, state and the enable boolean. This generates a lot of traffic as time constantly changes but there is an easy and efficient alternative way of doing this. You can make a network animation script which is serializes only a single char variable, and then in the animation script you send a message to this network script and tell it what the current animation state is. Only the single char variable is sent each time that animation changes, which is nothing compared to brute force synchronizing the animation.
When to synchronize data
Is it really necessary to always keep a game completely in sync on all clients? Think about a game where there are large buildings all over the place or big race tracks which go into forests or over and under hills. When one client is nowhere in sight of another client there is no need to keep them synchronized with each other. This can greatly decrease the load on the server as he no longer needs to tell everyone about everyone else. This is sometimes called using Relevant Sets. You have a set of relevancy for each client which defines what data he needs to receive. At the moment this can, however, only be done with RPCs as their destination scope has greater control. You can direct them to specific network players, based on your own logic on who should get them.
Level loading
One exception for when to worry about bandwidth is during startup or level loading. Here it is fine to send bulks of data to initialize the game, each client just waits until everybody is ready. You could even send textures or picture data so players can really customize their avatars.
Page last updated: 2009-11-23