Unity: Exploring Multiplayer Solutions

John Tucker
4 min readMay 31, 2018

Having learned the basics of Unity, I dove into my first project multiplayer project.

Unity Multiplayer High Level Scripting API (HLAPI)

The first solution that I considered, Unity Multiplayer High Level Scripting API (HLAPI), seemed like a good choice because it is in the official Unity manual. It also provides solution that is well-integrated with Unity, e.g., you add a NetworkTransform component to a GameObject to synchronize the players’ movements.

In Unity’s High Level API (HLAPI) system, multiplayer games include:

A server: A server is an instance of the game which all other players connect to when they want to play together. A server often manages various aspects of the game, such as keeping score, and transmit that data back to the client.

Clients: Clients are instances of the game that usually connect from different computers to the server. Clients can connect over a local network, or online.

A client is an instance of the game that connects to the server, so that the person playing it can play the game with other people, who connect on their own clients.

The server might be either a “dedicated server”, or a “host server”.

Dedicated server: This is an instance of the game that only runs to act as a server.

Host server: When there is no dedicated server, one of the clients also plays the role of the server. This client is the “host server”. The host server creates a single instance of the game (called the host), which acts as both server and client.

— Unity — Networking HLAPI System Concepts

My first concern about this solution was that it was not clear how the clients were to find a server (just another instance of the game) and once found how they were to communicate to it (through routers, firewalls, etc.). After a bit more reading, however, Unity provides two cloud services, Unity Matchmaker and Relay Services, that solve these problems. Unity Personal provides a free solution up to 20 concurrent players.

Another concern of the host server configuration is what happens when the host disconnects from the game, e.g., loses network connectivity? Again, Unity does provide a solution with the Host Migration feature.

In thinking about the dedicated server option, using Unity’s headless mode, I determined that this require me operating a host (e.g., an Amazon AWS EC2 instance). Not something that I was prepared to do.

As I was really more interested in a fully cloud-solution, I started exploring other options.

socket.io

Having written real-time web applications with socket.io, running a Node.js server on a Platform as a Service (PAAS) such as Heroku, I looked at several client implementations for Unity, e.g., socket.io-unity, but quickly found their documentation to be weak and I had troubles getting them up and running.

Firebase

Having also used Firebase’s real-time database, I explored their official Unity integration. The documentation was fairly complete and I was able to get up and running fairly quickly.

note: Firebase’s support of Unity with .NET 4.X was a little bit tricky; basically had to install Firebase with Unity with .NET 3.5 and then upgrade to .NET 4.X.

But… When I tried to build to the Android platform, I ran into all sort of errors (looked to be a .NET 4.X issue).

Fighting those errors gave me pause and reminded me that Firebase (like the socket.io solution) was also not deeply integrated with Unity; things like synchronizing player movement, etc., was going to be difficult.

Photon Unity 3D Networking

I then finally turned to Photon Unity 3D Networking (PUN); it tightly is integrated with Unity; much like Unity Multiplayer High Level Scripting API. At the same time it is a full cloud implementation.

PUN games are hosted in our globally distributed Photon Cloud to guarantee low latency and shortest round-trip times for your players worldwide.

Connect, Match and Play: PUN is the rock-solid foundation for any type of room based multiplayer game in Unity 3D. You concentrate on building a great title while we take care of the game’s backend.

Export to mobile, desktop, web or consoles: Photon is the standard cross-platform multiplayer service and the world’s #1 for Unity games.

Photon — Photon Unity 3D Networking

With it’s free 20 concurrent user plan (and scalable pricing) and excellent documentation I ended up quickly building my first multiplayer project with it.

Conclusion

Having explored a number of multiplayer solutions, I concluded that Photon Unity 3D Networking is the solution that I plan on building all my multiplayer projects with going forward.

--

--

John Tucker

Broad infrastructure, development, and soft-skill background