Sponsored By

Pitfalls of making fast multiplayer games on mobile with Unity's uNet

When you make a fast paced mobile game which happens to be multiplayer with unity and uNet. There are pitfalls which you should avoid and they might not be as clear if you are not aware of them. I'm trying to describe them here.

Ashkan Saeedi Mazdeh, Blogger

September 25, 2018

5 Min Read

I work on multiplayer games a lot and It is more than 8 years that i either worked on a game which was multiplayer, worked on servers for games or worked on multiplayer related middleware at MuchDifferent (If you remember uLink and its friends). Yes i worked on a few small single player titles but that has not been the majority of the cases.

On one of the projects i was working on which was a relatively fast action multiplayer title, i had to battle with a few issues which where not anticipated and costed me a lot of time. I'm writing them here so you can avoid the time waste and other potential costs.

I joined the project after it was in development for a good while and started to convert it from a none-authoritative setup to Unity's uNet with authoritative servers. It took me more than i estimated and told my employer to make some basic stuff running due to reasons below which I'm writing so others can avoid them.

Firstly the project was targeted at 30 frames per second and with the number of synced messages we wanted to have and the amount of interpolation backtime we chose, this meant more latency than needed. disabling the cap on server and setting it to 60 made me capable of lowering the interpolation backtime of players much lower.

Also uNet either introduced in the last 1.5 years which i did not make fast games with it or had from the beginning and i forgot a property in NetworkServer class called maxDelay which by default is set to 0.1 (i.e. 100ms) which means your data sent using HLAPI can be delayed up to 100ms before being sent by the framework. Sometimes and for some kinds of games this is a good value but for a game that you are updating some things 20 times a second this value should be at most 50ms and also things like time sync messages should be sent preferably using LLAPI to avoid this delay to be more accurate. The issue of time sync messages might be resolvable without reducing the delay for many syncing scenarios but you cannot send 20 position updates from an authoritative server successfully with 100ms of artificial delay and still keep the proxy objects interpolation backtime below 100ms even if you have 20ms of latency to the server. There are other values in the ConnectionConfig which help you combine packets before sending them with too much overhead but also can produce latency, check the documentation of the ConnectionConfig class to be aware of them and set them to appropreate values. I was aware of these and they did not present any issues for me but the NetworkServer.maxDelay one hunted me for few days unfortunately and i could not find out why the hell on earth things are getting delayed this much on the local host :(. I know i should knew my system better and i should have read the friendly manual again to make sure I'm not missing anything but i simply assumed the only place values like these are set is the ConnectionConfig.

Another issue which is not mobile specific is that uNet does not have a synchronized NetworkTime and can only calculate delays for you using the timestamps which it has and you should put some good amount of time for making a good NetworkTime class which synchronizes a global time value which is smooth and monotonic so it can be used in the game. Again this is not a particularly impossible task but still needs few days to make working well and even more if you want to build something as robust as what League of Legends does with its time.

uNet is spending its last months and yes it works. Back then in 2016 i converted two games to it and even made them work on PC, Mac, Mobile and WebGL using WebSockets and made it possible for WebGL players to cross-play. Back then either i found out the maxDelay thing much faster and fixed it or it had a different default value. Anyways i hope this post helps you to avoid these problems. Also I'm looking for development or consultancy work os if you have anything available just send me a an email or contact me on LinkedIn

Read more about:

Blogs
Daily news, dev blogs, and stories from Game Developer straight to your inbox

You May Also Like