Search Unity

How to choose the right netcode for your game

September 8, 2020 in Games | 6 min. read
Share

Is this article helpful for you?

Thank you for your feedback!

Almost all multiplayer games have to account for and solve inherent network-related challenges that impact the game experience, such as latency, packet loss, and scene management. Games solve these challenges in a variety of ways. 

Finding the right solution depends on your game’s genre, the scale of its players and networked objects, competitiveness, and other aspects, like how much control is needed over the networking layer. Different scenarios require different netcode solutions.

In this blog, we cover common networking libraries used in the Unity Engine, plus the results of a study conducted on developers’ experience with these solutions, to help you determine what might be right for your project.

What is netcode?

Netcode is a high-level term many engineers use to refer to frameworks that are specifically designed to help make building certain aspects of networked gameplay easier – like data synchronization or lag compensation.

A fully networked framework contains two essential components:

  1. A transport (base) layer that manages all traffic and packets sent to/from a client, host, or server
  2. A higher-level abstraction layer that simplifies common networking gameplay needs and integrates with tools

Oftentimes, a “netcode solution” refers to that second, abstraction layer, as this is where you implement your networked gameplay and optimizations.

Different netcode solutions have different limitations and capabilities that may make it easier or harder to build your multiplayer experience. It’s important to know exactly what you want to build and evaluate your options before you start, to help reduce refactors that could be expensive.

Unity’s netcode solutions

Unity has two different first-party netcode solutions: Netcode for GameObjects and Netcode for Entities.

Netcode for GameObjects

The Netcode for GameObjects package was built to help you more easily synchronize scenes and GameObjects data across multiple clients and platforms with either client- or server-authoritative models. The Unity engine helps you optimize your multiplayer games with tools to profile the network both in Play mode and at runtime.

You can also use Relay from Unity Gaming Services, which is a cost-effective peer-to-peer companion service, to scale playtests and build a multiplayer game without having to invest in dedicated hosting.

Netcode for Entities

Expand the range of possibilities in the upcoming Unity 2022 LTS. Add the ability to target competitive action multiplayer games with the Netcode for Entities package based on ECS, built for performance and scalability. You can target ambitious server-authoritative gameplay featuring prediction, interpolation, and lag compensation.

Manage the costs with a dedicated server build target that can automatically strip assets. Deploy it with Game Server Hosting from Unity Gaming Services, a streamlined approach to maintaining resiliency and scalability in your gaming infrastructure, so you can focus on providing the best experience to your players.

How to evaluate different netcode solutions

Unity has gathered feedback about some of the most widely used third-party netcode solutions, and we’ve created a decision tree to help guide you through the process of deciding which framework might work best for you.

To create these tools, we gathered and analyzed data from three sources:

  • A survey of over 200 Unity users that asked for information about their experiences with specific netcode frameworks
  • Over 20 in-depth interviews with users actively shipping multiplayer games with Unity
  • Learnings from prototypes we built with MLAPI (now known as Netcode for GameObjects), DarkRift 2, Mirror, and Photon Quantum.

Customers scored and ranked the top netcode solutions across different axes based on their experience.

1. Stability and support

Networking is complex, so the level of stability and support you receive through your netcode solution is critical. Stability and support of each netcode solution was evaluated along three axes – the likelihood of bugs or crashes, response time to fix issues or help debug a challenge, and the likelihood of breaking changes to the APIs.

2. Ease of use

We compiled users’ evaluations of how easy it is to get started and perform common tasks, including the provision of good samples, documentation, tutorials, and the solution’s offering of simple APIs for prototyping.

3. Performance

Who wants a solution that has poor performance? To score this for each netcode solution evaluated, we looked for limited GC/allocations, minimal latency overhead, performant compute, and ideally the ability to multithread.

4. Scalability

Depending on the genre of game you’re looking to create, scalability of the netcode solution is an important consideration. Similar to performance, we evaluated the solution’s ability to support a larger number of connected clients without a large sacrifice in performance.

5. Feature breadth

Having a fully-featured netcode solution is important to support any genre or unique game-specific needs your project has. For ranking the solutions, we focused on mid-level features like object and variable replication, RPCs, scene management, and so on. We also looked for higher-level features like prediction and lag compensation.

6. Cost

In order to properly budget for your netcode solution, we’ve included evaluations of the cost of each solution as well. This consideration factors in both the cost of the libraries/solution and possible hidden costs, such as operating overhead that has to be managed separately.

Which is the best netcode solution for you?

Before making a decision about a netcode solution, it’s important to take a few things into consideration.

First, we highly recommend that you still perform your own evaluation. Our summary of the most common options can be helpful, but you should also do an assessment based on the specifics of your game.

Secondly, this list is based on an evaluation run in 2020, and doesn’t represent all of the alternatives for netcode or transport layer solutions that are currently available.

Lastly, consider how much extra network-related work and maintenance you’re prepared to take on. Does your game need that much network overhead?

If you are building something casual or co-operative that doesn’t require perfect synchronization of all player states across devices, consider a netcode solution with less overhead and development cost like Netcode for GameObjects.

If you’re making a game that’s more fast-paced and action-oriented, where players’ physical skills are put in competition with each other, consider a solution like Netcode for Entities. This can support things like client prediction and has a method of compensating for lag.

2020 netcode solution evaluation

The information below is a start, but we recommend that you also download the full netcode report, where we go into greater detail about these third-party netcode solutions:

Note: The PDF covers solutions most referenced by customers, but there are more. Some customers discussed other solutions for which we haven’t yet gathered enough customer evidence to evaluate, such as Forge, Normcore, Bolt, LL (Enet, LiteNet, and so on). We encourage you to add these to your considerations to see if they would be an option for your setup.

Getting started with multiplayer development in Unity

Whether you’re building the next battle royale smash hit or a cozy online co-op, understanding the basics of multiplayer networking and the netcode solutions available to you is essential.

See Unity’s Boss Room co-op sample for a production quality example of a project made with Netcode for GameObjects. If you’re looking for an example of a fast-paced, competitive multiplayer game that is also network performant, check out Unity’s ECS Network Racing sample built with the Entities Component System. To see a game example that fully utilizes everything Game Server Hosting has to offer, check out the Battle Royale sample built with Photon Fusion.

Happy creating.

Editor’s note: This blog was updated in March 2023 with the latest information on Unity’s netcode solutions in order to provide more helpful information for developers choosing the right netcode solution for their game. The report data is still from 2020.

September 8, 2020 in Games | 6 min. read

Is this article helpful for you?

Thank you for your feedback!

Join a discussion on our Forums
Related Posts