Unity3D Networking and multiplayer
P2P_01

Unity3D Networking and multiplayer

2 years ago

There comes a time whern Unity3D developers start wondering – how to make a multiplayer game using this engine. So did we!

We are working on an ambitios project with Oculus (Gear VR + Samsung S6) project. Unity3D is more than capable to handle our needs. One of the future project’s feature is a simple multiplayer. And now we’re on a crossroads – what multiplayer should we choose for realtime manipulations.

Let me tell you something about Unity’s native networking. 

Till Unity 5 release there was a Network class, which allowed us to create servers and connect to those servers as a client. It worked rather simple. In 1 line of code you could start a server on a certain port, with another line of code you could connect to this server as a client, typing just this port and IP address of this newly created server. You could also create a dedicated server, allowing clients to connect. The only thing to worry is game logics and smoothing object movement. There were absolutely no problems connecting in local network, and there were some firewall, dedicated ip, port openning problems to connect using Internet – complex, but not impossible.

The only problem in this case is that developer or user should know exactly IP and port to connect to the game and we all know that casual gamers just want to play, remembering some digit sequence is not for them. Unity came up with a Master Server for this problem. A Master Server is middle man in connecting servers and clients. How Master Server works ? Master Server is a separate app, that can be compiled for any OS (you can google already compiled versions of Master Server on Unity’s support forum). The logic here is that when Unity app creates a game server it registers in the Master Server, saying “Hey, this computer with ip xxx.xxx.xxx.xxx and port xxxxx is hosting a server that’s called ‘some server’ with a certain game type”. On the other hand a client tryies to reach this Master Server by an IP and get the list of all servers hosted by other guys. So when a client get’s his list of servers he can connect to any server from that list. That way Master Server can be runned on a Virtual Server with a dedicated IP and this IP can be hardcoded in the game code. So the only 2 things that Master Server does is registering servers and sending a list of available servers when asked.

Unity even provided developers with their own Master Server but it was often down.

What happened in Unity 5 ?

Unity 5 brought a new networking model. From version 5.1 this new networking will be available to all users (including those who use free version). Unity 5 has a set of components that help creating a multiplayer games which are hosted and controlled by their own servers. Main components are Network Manager and Network Identity. The first one controlls entire connection, the second one tell all connected users that this object will be known and possibly synced with the server and other clients.

Currently Unity is going with Preview stage, which allows all developers creating their games with up to 100 concurent users for free. Nobody knows when this preview stage will be over and what will be the pricing on this server.

So if you’re planning to make a realtime Unity3D game, and your trying to build your backend server that will manage messages along your clients, or maybe trying to find a paid service to make it for you – consider using Unity’s network servers.

PRO’s

  • It’s currently free for 100 concurent users
  • Basic setup is easy as pie (like all Unity solutions)

CON’s

  • Nobody knows how much will it cost in future
  • Your game will be fully dependent on Unity cloud servers (no control over them)