Convert Figma logo to code with AI

Unity-Technologies logocom.unity.netcode.gameobjects

Netcode for GameObjects is a high-level netcode SDK that provides networking capabilities to GameObject/MonoBehaviour workflows within Unity and sits on top of underlying transport layer.

2,121
430
2,121
247

Top Related Projects

5,105

#1 Open Source Unity Networking Library

Netcode for GameObjects is a high-level netcode SDK that provides networking capabilities to GameObject/MonoBehaviour workflows within Unity and sits on top of underlying transport layer.

Lidgren Network Library

Lite reliable UDP library for Mono and .NET

Quick Overview

Unity-Technologies/com.unity.netcode.gameobjects is a high-level networking library for Unity, designed to simplify the process of creating multiplayer games. It provides a set of tools and APIs for synchronizing game objects, managing network connections, and handling client-server communication within Unity projects.

Pros

  • Easy integration with Unity's existing GameObject and MonoBehaviour system
  • Automatic network state synchronization for game objects
  • Built-in support for client-side prediction and server reconciliation
  • Scalable architecture suitable for both small and large multiplayer games

Cons

  • Learning curve for developers new to networking concepts
  • Limited customization options for advanced networking scenarios
  • Potential performance overhead compared to lower-level networking solutions
  • Dependency on Unity's ecosystem and update cycle

Code Examples

  1. Spawning a networked object:
public class SpawnManager : NetworkBehaviour
{
    public GameObject prefabToSpawn;

    [ServerRpc]
    public void SpawnObjectServerRpc(Vector3 position)
    {
        GameObject spawnedObject = Instantiate(prefabToSpawn, position, Quaternion.identity);
        NetworkObject networkObject = spawnedObject.GetComponent<NetworkObject>();
        networkObject.Spawn();
    }
}
  1. Synchronizing a custom variable:
public class PlayerController : NetworkBehaviour
{
    public NetworkVariable<int> Score = new NetworkVariable<int>();

    [ServerRpc]
    public void AddScoreServerRpc(int points)
    {
        Score.Value += points;
    }
}
  1. Sending a client RPC:
public class GameManager : NetworkBehaviour
{
    [ClientRpc]
    public void ShowMessageClientRpc(string message)
    {
        Debug.Log($"Received message: {message}");
    }
}

Getting Started

  1. Install the package via Unity Package Manager:

    • Open your Unity project
    • Go to Window > Package Manager
    • Click the "+" button and choose "Add package from git URL"
    • Enter: https://github.com/Unity-Technologies/com.unity.netcode.gameobjects.git
  2. Create a NetworkManager in your scene:

    • Right-click in the Hierarchy window
    • Select "Network > NetworkManager"
  3. Add NetworkObject component to GameObjects you want to synchronize:

    • Select the GameObject in the Hierarchy
    • Add Component > Network > NetworkObject
  4. Implement network behavior using NetworkBehaviour:

using Unity.Netcode;

public class MyNetworkedScript : NetworkBehaviour
{
    public override void OnNetworkSpawn()
    {
        if (IsServer)
        {
            Debug.Log("Running on server!");
        }
        else if (IsClient)
        {
            Debug.Log("Running on client!");
        }
    }
}

Competitor Comparisons

5,105

#1 Open Source Unity Networking Library

Pros of Mirror

  • More mature and stable, with a longer development history
  • Larger community and more extensive documentation
  • Offers a wider range of built-in features and components

Cons of Mirror

  • Less integrated with Unity's ecosystem
  • May require more manual setup and configuration
  • Potentially steeper learning curve for beginners

Code Comparison

Mirror:

using Mirror;

public class Player : NetworkBehaviour
{
    [SyncVar] public int health;
}

Netcode for GameObjects:

using Unity.Netcode;

public class Player : NetworkBehaviour
{
    public NetworkVariable<int> health = new NetworkVariable<int>();
}

Both libraries use similar concepts, but Mirror uses attributes like [SyncVar] for network synchronization, while Netcode for GameObjects uses NetworkVariable<T> objects.

Mirror tends to have a more straightforward approach to networking, while Netcode for GameObjects offers tighter integration with Unity's systems and potentially more flexibility in certain scenarios.

Ultimately, the choice between Mirror and Netcode for GameObjects depends on project requirements, team expertise, and personal preference. Both libraries are capable of creating multiplayer games in Unity, with their own strengths and trade-offs.

Netcode for GameObjects is a high-level netcode SDK that provides networking capabilities to GameObject/MonoBehaviour workflows within Unity and sits on top of underlying transport layer.

Pros of com.unity.netcode.gameobjects

  • Actively maintained and updated by Unity Technologies
  • Integrated with Unity's latest networking features
  • Extensive documentation and community support

Cons of com.unity.netcode.gameobjects

  • May have a steeper learning curve for beginners
  • Potential performance overhead for complex networked games
  • Limited customization options compared to some third-party solutions

Code Comparison

com.unity.netcode.gameobjects:

using Unity.Netcode;

public class PlayerController : NetworkBehaviour
{
    public override void OnNetworkSpawn()
    {
        if (IsOwner)
        {
            // Player-specific logic
        }
    }
}

Both repositories appear to be the same project, as they have identical names and are owned by Unity Technologies. Therefore, a code comparison between them is not applicable in this case.

Summary

com.unity.netcode.gameobjects is Unity's official networking solution for multiplayer game development. It offers robust features and integration with the Unity ecosystem but may require more effort to learn and optimize for complex projects. As both repositories mentioned are the same, there are no distinct differences to compare between them.

Lidgren Network Library

Pros of lidgren-network-gen3

  • Platform-independent networking library, usable in various game engines and frameworks
  • Lightweight and efficient, with low overhead for small-scale multiplayer games
  • Highly customizable, allowing developers to fine-tune network behavior

Cons of lidgren-network-gen3

  • Less integrated with Unity, requiring more manual setup and configuration
  • Smaller community and fewer resources compared to Netcode for GameObjects
  • May require more low-level networking knowledge to implement effectively

Code Comparison

lidgren-network-gen3:

NetPeerConfiguration config = new NetPeerConfiguration("SampleGame");
NetServer server = new NetServer(config);
server.Start();

com.unity.netcode.gameobjects:

public class NetworkManagerScript : NetworkManager
{
    public override void OnServerStarted()
    {
        // Server-specific logic
    }
}

The lidgren-network-gen3 code shows a more manual setup process, while com.unity.netcode.gameobjects integrates more seamlessly with Unity's component-based architecture. Netcode for GameObjects provides a higher-level abstraction, making it easier to implement networking features in Unity projects. However, lidgren-network-gen3 offers more flexibility for advanced users who need fine-grained control over network operations.

Lite reliable UDP library for Mono and .NET

Pros of LiteNetLib

  • Lightweight and efficient, with minimal overhead
  • Platform-independent, supporting various operating systems
  • Highly customizable with low-level network control

Cons of LiteNetLib

  • Requires more manual setup and configuration
  • Less integrated with Unity-specific features
  • Steeper learning curve for beginners

Code Comparison

LiteNetLib:

NetManager client = new NetManager(new EventBasedNetListener());
client.Start();
client.Connect("localhost", 9050, "SomeConnectionKey");

com.unity.netcode.gameobjects:

NetworkManager.Singleton.StartClient();
NetworkManager.Singleton.ConnectClient();

Summary

LiteNetLib offers a lightweight, platform-independent networking solution with fine-grained control, suitable for developers who need customization and efficiency. However, it requires more manual setup and may be challenging for beginners.

com.unity.netcode.gameobjects provides a more Unity-integrated approach, with easier setup and better compatibility with Unity's ecosystem. It's more beginner-friendly but may have less flexibility for advanced networking scenarios.

Choose LiteNetLib for performance-critical applications or cross-platform projects outside Unity. Opt for com.unity.netcode.gameobjects when developing Unity-specific games with simpler networking requirements or when rapid development is a priority.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

Netcode for GameObjects

Forums Discord Manual API

GitHub Release

Welcome!

Welcome to the Netcode for GameObjects repository.

Netcode for GameObjects is a Unity package that provides networking capabilities to GameObject & MonoBehaviour workflows. The framework is interoperable with many low-level transports, including the official Unity Transport Package.

Getting Started

Visit the Multiplayer Docs Site for package & API documentation, as well as information about several samples which leverage the Netcode for GameObjects package.

You can also jump right into our Hello World guide for a taste of how to use the framework for basic networked tasks.

Community and Feedback

For general questions, networking advice or discussions about Netcode for GameObjects, please join our Discord Community or create a post in the Unity Multiplayer Forum.

Compatibility

Netcode for GameObjects targets the following Unity versions:

  • Unity 2021.3(LTS), and 2022.3(LTS)

On the following runtime platforms:

  • Windows, MacOS, and Linux
  • iOS and Android
  • Most closed platforms, such as consoles. Contact us for more information about specific closed platforms.

Development

This repository is broken into multiple components, each one implemented as a Unity Package.

    .
    ├── com.unity.netcode.gameobjects           # The core netcode SDK unity package (source + tests)
    └── testproject                             # A Unity project with various test implementations & scenes which exercise the features in the above packages.

Contributing

We are an open-source project and we encourage and welcome contributions. If you wish to contribute, please be sure to review our contribution guidelines.

Issues and missing features

If you have an issue, bug or feature request, please follow the information in our contribution guidelines to submit an issue.

You can also check out our public roadmap to get an idea for what we might be working on next!