Unity Networking

13 min. read

Unity - Multiplayer is a complex beast, there are a number of different options available to both indie and AAA developers.

<! – more –>

Introduction

If you’re making a turn-based, or MMOFPS game, you will need some sort of backend. This article will go over some of the options available.

Networking Options

  1. Unet
  2. Unity built-in - Dont use
  3. Unity’s New Networking Solution…
  4. When ever that is ready
  5. Mirror
  6. Used in uMMORPG
  7. Stream
  8. For chat only
  9. Photon Fusion
  10. New PUN, also better than Photon Bolt - Good for fast-paced FPS
  11. Netcode
  12. New Unity solution
  13. https://blog.unity.com/games/enter-the-boss-room-in-2022-netcode-for-gameobjects-relay-and-lobby
  14. https://github.com/Unity-Technologies/com.unity.multiplayer.samples.coop
  15. Fish-Net
  16. https://fish-networking.gitbook.io/docs/
  17. https://github.com/FirstGearGames/FishNet/tree/main/Assets/FishNet/Runtime
  18. https://assetstore.unity.com/packages/tools/network/fish-net-networking-evolved-207815
  19. Dark-rift 2
  20. SmartFox Server
  21. Custom Server using Sockets.

Prerequisites

This article assumes that you have some basic knowledge of the following topics:

Backend-as-a-Service

Photon

Photon has a number of offerings:
https://www.photonengine.com/en-US/Photon

Photon Realtime

https://www.photonengine.com/en-US/Realtime

Photon PUN

https://www.photonengine.com/en-US/PUN

Photon BOLT

https://www.photonengine.com/en-US/BOLT

Photon Quantum

https://www.photonengine.com/en-US/Quantum

UDP on all platforms and Websockets on WebGL
relay service

https://doc.photonengine.com/en-us/server/current/reference/authoritative-server
https://doc.photonengine.com/en-us/server/current/getting-started/photon-server-intro
Photon Bolt
https://www.photonengine.com/en-US/BOLT/pricing
https://assetstore.unity.com/packages/tools/network/photon-bolt-free-127156
https://www.photonengine.com/en/Bolt
https://doc.photonengine.com/en-us/bolt/current/getting-started/overview

Cons:
Still, require you to handle Load Balancing
Server

Photon Server

https://www.photonengine.com/en-US/Server
https://doc.photonengine.com/en-US/Server/current/operations/requirements

PUN vs Bolt vs Server vs Quantum

Playfab

Doom Eternal is also using Playfab

Playfab folder

https://api.playfab.com/blog/a-free-playfab-custom-game-server

https://github.com/PlayFab/PlayFabGameServer

https://api.playfab.com/docs/tutorials/landing-tournaments/custom-game-servers

https://github.com/PlayFab/PlayFabGameServer

https://strangeioc.wordpress.com/

https://community.playfab.com/questions/22352/multiplayer-with-authoritative-server-hosted-by-pl.html

https://github.com/PlayFab/PlayFabGameServer

Multiplayer Servers
https://docs.microsoft.com/en-us/gaming/playfab/features/multiplayer/servers/

https://www.quora.com/Who-are-the-competitors-to-PlayFab-Inc-the-BaaS-for-games

Gamesparks

Pros
NodeJS

Cons
Price?

https://www.gamesparks.com/product/real-time-multiplayer/

Realtime Services

BrainCloud

https://portal.braincloudservers.com/admin/dashboard#/support/company
https://braincloud.statuspage.io/
http://18.220.113.13/apidocs/tutorials/unity-tutorials/braincloud-bombers-example-game/
https://getbraincloud.com/apidocs/tutorials/unity-tutorials/building-the-braincloud-bombers-project/

Realtime Multiplayer: They use PUN.

Google Play Game Services (Android Only)

https://developers.google.com/games/services/cpp/realtimeMultiplayer

Nakama

https://heroiclabs.com/

https://heroiclabs.com/docs/nakama-download/

https://forum.defold.com/t/infos-about-a-multiplayer-game-service-server-provider/12888

SpatialOS

Google-partnered

https://forums.improbable.io/t/unity-webgl-support/3561

No WebGL support
Lack of decent tutorials/documentation

Chilli connect

Website: https://www.chilliconnect.com/
Documentation: https://docs.chilliconnect.com/guide/

Multiplay

https://multiplay.com/

https://multiplay.com/services/dedicated-game-server-hosting/#:~:text=Prices%20for%20Multiplay's%20Managed%20Infrastructure,due%20to%20the%20variables%20involved.

Parse

https://parseplatform.org/

Back4App

https://www.back4app.com/

App42

http://api.shephertz.com/app42-dev.php
http://www.shephertz.com/

Firebase

https://firebase.google.com/games

Player.io

https://playerio.com/

Platform-as-a-Service (PaaS)

See the Cloud Deployment Section below

Custom Server

Going with your own server, requires a number of components:

Backend Platform
Database
Caching
Deployment
Communication Protocol
Load Balancing

Backend Platform

The Backend platform or language you use will mostly depend on your skills, experience, business needs, cost, etc..

Unity

uNet - Unity Multiplayer High Level Scripting API (HLAPI)

Note: UNet is deprecated, and will be removed from Unity in the future

https://docs.unity3d.com/2020.1/Documentation/Manual/UNet.html

Mirror

Read more about Mirror

uMMORPG

https://assetstore.unity.com/packages/templates/systems/ummorpg-51212

https://noobtuts.com/unity/unet-server-hosting

https://noobtuts.com/unity/detect-headless-mode

https://docs.google.com/document/d/e/2PACX-1vQqf_iqOLlBRTUqqyor_OUx_rHlYx-SYvZWMvHGuLIuRuxJ-qX3s8JzrrBB5vxDdGfl-HhYZW3g5lLW/pub

ForgeNetworkingRemastered

Read More About Forge Networking

NodeJS

NodeJS Multiplayer Packages

Socket.io

https://medium.com/containers-on-aws/building-a-socket-io-chat-app-and-deploying-it-using-aws-fargate-86fd7cbce13f

https://medium.com/@eyalronel1984/auto-scaling-real-time-nodejs-applications-on-aws-the-last-tutorial-youll-need-eba1d2c88a4c

https://stackoverflow.com/questions/53195424/aws-load-balancer-and-autoscaling-for-nodejs-using-socket-io

https://stackoverflow.com/questions/43702043/aws-application-load-balancer-and-socket-io

https://stackoverflow.com/questions/23924718/socket-io-with-aws-elastic-load-balancer

https://www.reddit.com/r/gamedev/comments/6gjgnx/backend_scaling_for_multiplayer_html5_games/

https://www.quora.com/What-are-the-best-practices-to-scale-Node-js-backend-in-AWS-that-uses-SocketIO-for-realtime-messaging

WS

https://www.npmjs.com/package/ws

Lance GG

https://lance-gg.github.io/

Colyseus

https://github.com/colyseus/colyseus

https://colyseus.io/

Actionhero

https://github.com/actionhero/actionhero

Ably.io

https://www.ably.io/

ASP.Net

PHP

Java

Databases

MongoDB

Postgres

Firebase Realtime Database

Firebase Cloud Firestore

Cassandra (NoSQL Database)

Developed by Facebook
Apache project
Distributed Hashtable
Scales horizontally
Redundant
Limited queries (CQL)

Caching

Redis

Network Communication Protocol

HTTP

RESTful

Long Polling

WebSockets

Pros
Supports WebGL

MQTT

Cloud Deployment

AWS

Amazon GameLift

https://aws.amazon.com/gamelift/getting-started/

Lumberyard: GSG 001 - Introduction - First Time Launch
https://www.youtube.com/watch?v=NNqTDoPszxM&list=PLuGWzrvNze7KbG2x6ccIw8eMhL5e4Iwpe

Sign up for an AWS Free Tier and Test Amazon GameLift
https://www.youtube.com/watch?v=OboeAg3_v8Q&list=PLuGWzrvNze7KQO5mREeae2eIR8rJws0At

Getting Started: Downloading and installing Lumberyard 1.7
https://www.youtube.com/watch?v=-VH_7AVI4vE&list=PLuGWzrvNze7LUPx6acEXNhIL3S7jW3MC8

{\n “FleetId”: “fleet-7c041305-fb5b-45b8-900a-cd31b3ecfc74”,\n “GameSessionId”: “arn:aws:gamelift:us-east-1::gamesession/fleet-7c041305-fb5b-45b8-900a-cd31b3ecfc74/gsess-c04edca3-9857-44f8-bc1f-32a1e52f0d8b”,\n “IpAddress”: “35.174.4.81”,\n “PlayerId”: “Player 1”,\n “PlayerSessionId”: “psess-e2fe7226-52ad-42f0-82bc-1efa4b4423a1”\n}

{\n “FleetId”: “fleet-7c041305-fb5b-45b8-900a-cd31b3ecfc74”,\n “GameSessionId”: “arn:aws:gamelift:us-east-1::gamesession/fleet-7c041305-fb5b-45b8-900a-cd31b3ecfc74/gsess-c04edca3-9857-44f8-bc1f-32a1e52f0d8b”,\n “IpAddress”: “35.174.4.81”,\n “PlayerId”: “Player 2”,\n “PlayerSessionId”: “psess-be6b9a35-ca74-4d58-9972-956a6a730e28”\n}

yum install unzip

Heroku

Agones

Dedicated Game Server Hosting and Scaling for Multiplayer Games on Kubernetes https://agones.dev
https://github.com/GoogleCloudPlatform/agones

Linode

https://manager.linode.com/linodes/add

Digital Ocean

Azure

https://azure.microsoft.com/en-us/solutions/gaming/#related-products

GCP

Google App Engine
https://cloud.google.com/appengine/
https://cloud.google.com/docs/games

GCP - Agones

https://agones.dev/site/

https://www.youtube.com/watch?v=jEd3nfjKlCs
https://www.youtube.com/watch?v=XD1nuASFY3k
https://www.youtube.com/watch?v=CLNpkjolxYA
https://www.youtube.com/watch?v=Fro1IEbiqAY&list=PLIivdWyY5sqKICqivS8r25vm_tskHanqu
https://github.com/googleforgames/agones

Payment Systems

https://xsolla.com/products/paystation

Courses

Fundamentals of Multiplayer Development in Unity

References

General Networking

https://medium.com/swlh/building-a-realtime-multiplayer-browser-game-in-less-than-a-day-part-2-4-f1f109761cf3

Firebase vs Playfab vs Gamesparks

https://forum.unity.com/threads/firebase-vs-playfab-vs-gamesparks.451840/

Unity Networking uNet

https://blogs.unity3d.com/2018/08/02/evolving-multiplayer-games-beyond-unet/?_ga=2.173829219.1302133033.1605516700-463219548.1576656230

https://docs.unity3d.com/2020.1/Documentation/Manual/UNet.html

https://docs.unity3d.com/Manual/UNetLobby.html

https://docs.unity3d.com/Manual/MobileNetworking.html

https://docs.unity3d.com/Manual/UNetClientServer.html

Unity Connected Games

Connected Games: Building real-time multiplayer games with Unity and Google - Unite LA

Multiplayer In Unity3D - The REAL Options? NEW unity networking & more?

Games

Pokémon Go Technologies

PUN

https://www.red-gate.com/simple-talk/dotnet/c-programming/creating-multiplayer-games-with-unity-and-pun/

https://forum.unity.com/threads/help-on-choosing-the-best-tool-for-multiplayer-game-photon-gamesparks-etc.446361/

https://forum.unity.com/threads/a-realtime-multiplayer-game-with-facebook-friends-from-scratch.387329/

http://undertheweathersoftware.com/multiplayer-network-solutions-for-unity-photon-and-playfab/

https://unity3d.com/unity/features/multiplayer

https://answers.unity.com/questions/690123/where-to-start-with-real-time-multiplayer.html

https://www.theseus.fi/bitstream/handle/10024/136944/Ahde_Jani.pdf?sequence=1&isAllowed=y

Google Play
https://www.youtube.com/watch?v=fM87eDzhalc

Building a Scalable Multiplayer Backend in 5 Minutes
https://www.youtube.com/watch?v=3uqMdsrpzEU

Unite Europe 2016 - Building a PvP focused MMO
https://www.youtube.com/watch?v=x_4Y2-B-THo

Unite Europe 2017 - Photon vs UNet: multiplayer architecture explained
https://www.youtube.com/watch?v=Y1my5bKhKJY

Photon Auth Server
https://doc.photonengine.com/en-us/server/current/reference/authoritative-server

https://github.com/markmandel

https://en.wikipedia.org/wiki/Game_server#Dedicated_server

Valve
https://developer.valvesoftware.com/wiki/Latency_Compensating_Methods_in_Client/Server_In-game_Protocol_Design_and_Optimization

https://medium.com/javascript-multiplayer-gamedev/chronicles-of-the-development-of-a-multiplayer-game-part-1-89e3598e91ee

https://medium.com/javascript-multiplayer-gamedev/chronicles-of-the-development-of-a-multiplayer-game-part-2-loops-and-leaks-10b453e843e0#.gucg9tr0y

https://medium.com/javascript-multiplayer-gamedev/chronicles-of-the-development-of-a-multiplayer-game-part-3-your-turn-8a2b97951060

Firebase

https://firebase.google.com/games

Improbable (SpatialOS)

https://improbable.io/multiplayer-networking

Chronicles of Elyria is dropping virtual world platform SpatialOS
https://massivelyop.com/2018/01/12/chronicles-of-elyria-is-dropping-virtual-world-platform-spatialos/

https://soulboundstudios.com/

Chronicles of Elyria
https://www.chroniclesofelyria.com/

“I want the industry to believe in online games again,”

https://massivelyop.com/2017/05/23/improbables-plan-for-rescuing-the-mmo-genre-from-nuclear-winter-involves-a-crapton-of-money/

Socket.io

https://socket.io/docs/using-multiple-nodes/

https://redis.io/topics/pubsub

https://medium.com/containers-on-aws/scaling-a-realtime-chat-app-on-aws-using-socket-io-redis-and-aws-fargate-4ed63fb1b681

https://stackoverflow.com/questions/38701647/scalable-architecture-for-socket-io

https://www.quora.com/How-do-I-scale-socket-io-servers-2

https://blog.jayway.com/2015/04/13/600k-concurrent-websocket-connections-on-aws-using-node-js/

http://buildnewgames.com/real-time-multiplayer/

http://buildnewgames.com/websockets/

http://buildnewgames.com/optimizing-websockets-bandwidth/

https://medium.com/containers-on-aws/building-a-socket-io-chat-app-and-deploying-it-using-aws-fargate-86fd7cbce13f

https://github.com/socketio/socket.io

https://stackoverflow.com/questions/14754431/multiple-dynos-on-heroku-socket-io-broadcasts

https://stackoverflow.com/questions/11064826/using-socket-io-and-redis-on-heroku-with-node-js

https://stackoverflow.com/questions/26217312/socket-io-and-multiple-dynos-on-heroku-node-js-app-websocket-is-closed-before/31481025

https://socket.io/docs/using-multiple-nodes/

https://devcenter.heroku.com/articles/session-affinity

https://stackoverflow.com/questions/28842266/scaling-to-2-dynos-on-heroku-with-socket-io-redis-and-redistogo

https://elements.heroku.com/buttons/heroku-examples/node-socket.io-chat-redis

https://elements.heroku.com/buttons/heroku-examples/socket.io-whiteboard

https://blog.heroku.com/session-affinity-ga

Unet vs Photon Engine - A comparison

https://www.reddit.com/r/Unity3D/comments/9hzkk7/no_good_way_to_do_authoritative_server/

Testing

https://artillery.io/

https://www.artillery.io/docs/guides/guides/socketio-reference