Search Unity

How to choose the right netcode for your game

September 8, 2020 in Technology | 6 min. read

Editor’s note: This blog was updated in November 2022 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.

Almost all multiplayer game has to account for and solve inherent network-related challenges that impact the game experience, such as latency, packet loss, and scene management, and 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 the “create” half of the multiplayer story. Specifically, it is how developers refer to the libraries that send bits of data from one player to another, and then they synchronize those bits into a consistent game state. It’s also how we deal with speed-of-light limits and latency waiting for data to arrive.

A full solution is often broken down into the transport (base) layer that manages all traffic to/from hardware, and higher-level netcode abstractions and tools that simplify common needs.

There’s no perfect, one-size-fits all solution for all kinds of games and experiences. For example, an FPS game running on a dedicated game server with server authority for cheat prevention, such as Apex Legends, will have completely different netcode requirements than a MOBA running on a P2P topology with deterministic rollback for cheat mitigation like Heroes Strike.

Because there’s no single netcode solution for all scenarios, developers need to evaluate the options and decide which netcode solution – or combination of solutions – best suits a title’s needs. In many cases, they may also need to extend or customize existing netcode.

Unity’s netcode solutions

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

Netcode for GameObjects

Netcode for GameObjects is a networking library built for the Unity game engine. The current release of NGO focuses primarily on supporting the creation of small scale cooperative games and it pairs well for P2P games in this category with the Unity Relay and Unity Lobby solutions.

Netcode for Entities

At the other end of the multiplayer development spectrum is Netcode for Entities. This ships as part of our DOTS ECS (Entity-Component-System) feature set, empowering you to create scalable multiplayer worlds for your players.

Netcode for Entities can enable you to increase your game world size, player counts, and complex network interactions without the performance sacrifices developers have traditionally had to deal with.

Read more about the Unity 2022.2 Tech Stream release in our blog.

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 jumping into our study’s results and recommendations, it’s important to stress three points.

First, choosing a netcode solution for your game is a critical decision, and you should still perform your own evaluation. We want to make the process easier for you by sharing our summary of the most common options, but you should do your own assessment as well, based on the specifics of your game. 

Second, this list doesn't represent all of the alternatives, especially at the transport level, where many solid solutions exist, such as Enet, LiteNetLib, Ruffles, Telepathy, and others.

Third, this data is from our research done in 2020, and further research may be required to fully grasp the solutions as they stand today.

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 set-up.

High-level guide to starting to evaluate a netcode solution

We’ve also created a diagram to help walk you through the process of making this critical decision. Please keep in mind that all abstractions miss critical details – we can’t possibly share every technical variable that might influence your decision – but these are some of the elements you should consider as you start evaluating solutions to support your game’s pathway to success.

Here’s a quick glossary of some of the key terms used in the decision-making tree, and what do we mean by them.

  • Dedicated game server (DGS):  A client-server network implementation where the server is hosted on a dedicated computer – i.e., separately from the client devices. This option is expensive, but scalable and secure.
  • Listen server:  A client-server implementation where the server is hosted on a client device. It’s inexpensive, but not scalable and not secure.
  • Deterministic lockstep: A P2P implementation where only inputs are sent to all other players and synchronized in a “locked step” (i.e., synced for the same simulation tick all at once), and determinism on each client ensures that they all stay at the same state. This system is inexpensive and secure, but with complex determinism.
  • Deterministic rollback: An enhancement of deterministic lockstep where clients forward-predict inputs while waiting for updates. This setup is more complex but enables a more responsive game than lockstep. It’s relatively inexpensive and secure, but with very complex determinism and simulation.

To see our analysis in more detail, check out the full report. This in-depth overview will be more comprehensible if you have some familiarity with multiplayer and networking concepts.

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.

Check out Unity’s Netcode for GameObjects solution, our Boss Room co-op sample, and documentation to get started with your next multiplayer project today. Or, if you’re looking to build a multiplayer game at a larger scale, check out our Battle Royale sample with Photon Fusion and Game Server Hosting.

Happy creating.

September 8, 2020 in Technology | 6 min. read