Unity Multiplayer Documentation

repository·main·Indexed 20 days ago

https://github.com/unity-technologies/com.unity.multiplayer.docs

Documentation for Unity Multiplayer technologies, featuring Netcode for GameObjects. It covers high-level networking libraries for synchronizing GameObjects, the BufferSerializer for bi-directional serialization, and client anticipation models using AnticipatedNetworkVariable and AnticipatedNetworkTransform to improve responsiveness and conceal latency.

Tokens
171.9K
Snippets
263
Records
728
Agent score
71%

What's inside com.unity.multiplayer.docs

  1. Overview of Multiplayer Play Mode

    main

    Multiplayer Play Mode allows you to test multiplayer functionality directly within the Unity Editor. It enables you to simulate up to four Players simultaneously on a single development device using the same source assets on disk. This workflow helps reduce project build times and allows for local testing of server-client relationships.

    Supported Players:

    • 1 main Editor Player
    • Up to 3 Virtual Players
  2. Overview of Multiplayer serialization support

    main

    The Unity Multiplayer framework provides built-in serialization for C# primitives and Unity primitive types. For custom user-defined types, you can extend the network serialization system by implementing specific interfaces to control how data is transmitted over the network.

    Supported serialization methods include:

    • Built-in Primitives: Automatic support for C# and Unity primitive types.
    • Enum Types: Serialization for enumeration values.
    • Collections: Support for Arrays.
    • Strings: Support for FixedString types.
    • Custom Types: Implementation of the INetworkSerializable interface for manual control.
    • High-Performance Serialization: Implementation of the INetworkSerializeByMemcpy interface for memory-copy based serialization.
    • Component Serialization: Specialized serialization for NetworkObject and NetworkBehaviour components.
  3. Summary of latency issues and solutions

    main

    When designing multiplayer games, latency affects three core pillars. Use the following mapping to choose your architectural approach:

    Issue to solveHow to solve it
    SecurityServer authority
    ResponsivenessPrediction, action casting, client authority
    Accuracy/consistencyServer rewind, server authority

    Waiting for server responses before updating the client makes the game feel unresponsive. However, naive attempts to fix responsiveness can compromise security or simulation accuracy.

    | Issue to solve | How to solve it |
    | :--- | :--- |
    | Security | Server authority |
    | Responsiveness | Prediction, action casting, client authority |
    | Accuracy/consistency | server rewind, server authority |
  4. Main features of Transport 2.0

    main

    Transport 2.0 introduces several key improvements over previous versions:

    • WebGL Support: The package is now compatible with all Unity Engine supported platforms.
    • WebSocket Implementation: Access to WebSocket transport with or without TLS. Supported on every platform as Client or Server, and for WebGL as Client only.
    • Transparent Network Migration: Supports client-side network migration (e.g., moving across cell towers) for UDP transport.
    • Relay Integration: Improved integration with Unity Relay via a new API that abstracts boilerplate code.
    • Logging Integration: If the com.unity.logging package is installed, logs are routed through its default logger instead of UnityEngine.Debug.
  5. New features in the Lobby service

    main

    The Lobby service introduces several features not present in UNet Matchmaking:

    • Host Migration: Supports migrating the host role within a lobby.
    • QuickJoin API: Performs a query-and-join operation in a single step.
    • Custom Lobby and Player Data: Supports custom data with advanced updating, querying, and access control.
    • Query Filters and Ordering: Allows filtering and ordering results based on custom lobby data and default metadata.
    • Relay Integration: Can be integrated with the Relay service to keep lobby and relay session membership in sync.
    • Lobby Locking: You can lock a Lobby via Create or UpdateLobby APIs to prevent new players from joining (e.g., during active gameplay).
    • GetJoinedLobbies API: Allows a client to retrieve all lobbies the currently logged-in player belongs to if they lose track of their current sessions.
  6. Legacy ClientRpc usage in Netcode for GameObjects

    main

    :::warning ClientRpc and ServerRpc are legacy features of Netcode for GameObjects and have been replaced with the universal RPC attribute. This documentation is for legacy use. For current projects, use RPCs instead. :::

    In legacy Netcode for GameObjects, a ClientRpc allows the Server to invoke a method that executes on all connected clients. This is useful for broadcasting state changes or events from the server to the client-side representations of NetworkObjects.

  7. Use ServerRpc for legacy Netcode for GameObjects

    main

    :::warning ClientRpc and ServerRpc are legacy features of Netcode for GameObjects and have been replaced with the universal RPC attribute. This documentation is for legacy use. For current projects, use RPCs instead. :::

    A ServerRpc allows a client to send information to a server by invoking a method. It is a remote procedure call that can only be invoked by a client and is always executed on the server/host.

  8. Main features of Unity Transport 2.0

    main

    Unity Transport 2.0 introduces several key improvements over previous versions:

    • WebGL Support: The package is now compatible with all Unity-supported platforms, including WebGL.
    • WebSocket Implementation: Provides WebSocket transport with or without TLS. This is supported on all platforms as both Client and Server, but for WebGL, it is supported as Client only.
    • Transparent Network Migration: Supports client-side network migration (e.g., moving across cell towers) for UDP transport.
    • Relay Integration: Improved integration with Unity Relay via a new API that reduces boilerplate code.
    • Logging Integration: If the com.unity.logging package is installed, Transport logs are routed through its default logger instead of UnityEngine.Debug.
  9. Using Network Scene Visualization (NetSceneVis)

    main

    Network Scene Visualization (NetSceneVis) is a tool within the Multiplayer Tools package that allows you to visualize and debug network communication directly in the Unity Editor Scene View. It provides real-time visual feedback on bandwidth usage and object ownership using mesh shading and text overlays.

    Once the Multiplayer Tools package is installed, a Network Visualization toolbar appears in the Unity Editor Scene View. You can use this toolbar to toggle between different visualization modes.

  10. Test multiplayer instances with Play Mode Scenarios

    main
    Use the Play Mode Scenarios window to test one or more instances of a multiplayer project. This tool allows you to simulate multiplayer gameplay by running instances on a local device or a remote server, replicating environments where multiple users access the project from different locations with varying limitations. It is particularly useful for testing multiplayer gameplay across different platforms simultaneously.