Inmultiplayer games, clients need to be synced. It's possible to exchange data packets directly from your transport, but this can be complex for devs with little experience. So, let's look at some ready-made networking solutions for all sorts of use cases.
Hello! I'm Dmitrii Ivashchenko, a Lead Software Engineer at MY.GAMES. Our series of articles about the Unity realtime multiplayer landscape in 2023 continues! Today's topic concerns the ready-made solutions for real-time multiplayer that are available for us. Let's get started.
In multiplayer games, servers and clients exchange data by sending packets over the network. In order to create a shared virtual space for players who are connecting from different locations, events in the game process (like character movements or object creation) are synchronized with other clients by sending them data packets. The responsible party for sending and receiving packets over the network is called the transport layer.
It's theoretically possible to send these packets by directly calling the send functions of your transport, this approach can quickly become inconvenient for developers who have little experience working with multiplayer games. So, it's a better idea to use one of those listed below, stead of writing your own from scratch. Let's look at those solutions.
Unity Relay is a way for game developers to provide enhanced connectivity between players via a join code mechanism, without the need for investing in third-party solutions, maintaining dedicated game servers (DGS), or worrying about network complexities in multiplayer games. Instead of using DGS, the Relay service provides connectivity through a universal Relay server, acting as a proxy.
The Relay service allows players to communicate over several different protocols, including UDP, DTLS, and secure WebSocket (WSS). After selecting a Relay server, clients communicate directly with the Relay server using one of the aforementioned protocols. WebSocket connections allow for multiplayer connectivity in browsers using WebGL.
Unity Transport effortlessly supports all of the platforms supported by Unity Engine, thanks to a connection-based abstraction layer (built-in network driver) provided on top of UDP and WebSockets. You can configure UDP and WebSockets with or without encryption. You can also use pipelines to get additional functionality such as reliability, packet ordering, and packet fragmentation.
The main features of Transport 2.0 include added support for WebGL; this allows the Unity Transport package to be used on all supported platforms of Unity Engine. Transport users now have access to our implementation of Websocket transport, with or without TLS. Players on the move can now take advantage of transparent network migration, typically between cellular towers. This feature is currently limited to the client side and for UDP transport.
The recommended best practice is to use NGO (in most cases) because it offers a stable set of core features such as network variables, scene management, remote procedure calls (RPCs), and messaging. However, with its simplicity and ease of use, API Mirror Networking is also great for games that don't require the complete set of features provided by NGO.
Photon Realtime is the core layer for multiplayer games (and more complex network solutions from Photon). It deals with problems like player matchmaking and fast communication using a scalable approach. Photon Realtime is used both in games and in more specific multiplayer solutions.
Photon Cloud is a fully-managed service that provides global hosting for Photon Realtime clients. The game code communicates with Photon Cloud, connecting to the cloud, and using its API to perform actions such as connection, joining a random room, or raising events.
Photon Fusion is a new high-performance library for network state synchronization for Unity. It supports two fundamentally different network topologies and a mode for one player without a network connection using a single API.
Fusion is designed with simplicity in mind for integration into the Unity workflow, and offers advanced features such as data compression, client-side prediction, and delay compensation "out of the box".
In Fusion, for example, RPC and network state are defined by attributes on MonoBehaviour methods and properties, without the need for explicit serialization code, and network objects can be defined as prefabs, using all the latest Unity prefab features.
Fusion uses a modern compression algorithm to reduce bandwidth requirements with minimal overhead on the processor. Data is sent either as full compressed snapshots or as partial blocks with subsequent consistency achieved. In the latter case, a fully customizable interest area system is provided, allowing for very large player counts.
Fusion implements tick-based simulation and operates either in Shared mode or Host mode. The main difference is who has authority over network objects, but this in turn determines which other SDK features are available.
Fusion was developed to replace two existing Photon products for Unity (Bolt and PUN). The important core components of Fusion are NetworkRunner and NetworkObject. NetworkRunner can be considered as the core of Fusion - there is one runner in the scene that manages network operations and simulation.
Fusion supports RPC (Remote Procedure Calls) for cases where standard Fusion input or use of [Networked] properties is not the most practical solution. To get started with Fusion, we recommend studying the Fusion Getting Started Guide.
Photon Quantum is a fully deterministic engine for multiplayer games. It's based on the prediction/rollback approach, which is perfect for online games that are sensitive to delays, such as action RPGs, sports games, fighting games, FPS, and so on.
When using this engine, there is no need for netcode; all game elements are networked by default and 100% synchronized. You just need to create one simulation with multiple connected players, as when developing a local multiplayer experience. Quantum's deterministic subsystems ensure that simulations on each client are always synchronized and without delays, including: physics, bots, pathfinding, animation.
Player input is sent to the Photon Cloud servers and is then distributed among the other players. Webhooks can be used to connect your own backend and plugins for executing custom code on the server side.
Simulations encoded in Quantum have no dependencies on Unity and can run anywhere. All local actions are performed without delay, and remote inputs are predicted and rolled back. Quantum has the ability to view replays. Replays can be saved on the backend or used in-game. To get started, you can check out the Quantum 100 series.
Normcore automatically synchronizes all object transformations when you add the RealtimeTransform component to it. This doesn't require any coding. Additionally, Normcore offers state-dependent interpolation and reliable network physics for perfect movement in any connection.
One of the key advantages of Normcore is its fast data transport based on WebRTC. It uses the maximum packet size that does not cause fragmentation during transmission, which speeds up the data transfer process. All data packets in Normcore are encrypted by default, ensuring the security and confidentiality of user data.
Normcore also uses a delta update system. This means that it tracks all changes since the last packet was sent, and when it's time to send a new packet, it already knows what to include in it. This saves resources and improves performance. Data serialization features in Normcore allow for CPU usage optimization. All serialization code is automatically generated prior to project compilation, ensuring fast and efficient resource usage.
Normcore servers operate in regions worldwide and are connected through a private fiber optic network, which provides low latency. You can host Normcore on your own servers or allow Normcore to host a private copy of our cloud infrastructure for you.
Mirror Networking is a high-level network library for Unity, optimized for ease of use and reliability. This library is designed to simplify the process of working with network connections, allowing developers to focus on creating their projects.
Mirror Networking is compatible with over a dozen low-level protocols and constantly evolves and improves. It includes features for remote procedure calls and context management over the network and also supports working with physics in networked applications.
The library offers over a dozen built-in network adapters and five network management system options, allowing developers to create custom versions. Several complete usage examples are also included to facilitate the learning and coding process.
Nakama by Heroic Labs is a popular open-source game server that allows you to own your entire infrastructure in one open package. Nakama includes all the necessary real-time gaming APIs and social and competitive features.
Equipped with all the necessary features for your game, such as real-time multiplayer and social and competitive functions, Nakama allows you to customize all aspects both on the client and server-side using Go, TypeScript, and Lua. With Nakama, you can create real-time multiplayer competitive games, customize matchmaking algorithms, add daily rewards, create leaderboards, implement in-game currencies, and provide real-time chat.
Fish-Networking is a free, open-source library for networking solutions in Unity, developed by an experienced game designer. It offers an extensive set of features that are usually only available with paid solutions.
The main advantages of Fish-Networking are bandwidth and resource optimization (which can save on server costs), support for a large number of players (from dozens to hundreds), and built-in features such as client prediction, latency compensation, server load balancing, and support for nested network objects.
The following table provides an overview of various network solutions for game development on Unity, comparing them by the protocols used, supported topologies, maximum number of players per session, the minimum supported Unity version and current status as of mid-2023.
 3a8082e126