Unity Multiplayer Documentation
repository·main·Indexed 20 days ago
https://github.com/unity-technologies/com.unity.multiplayer.docsDocumentation 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.
What's inside com.unity.multiplayer.docs
- Netcode for GameObjects is a high-level networking library for Unity designed to abstract low-level networking logic. It allows developers to synchronize GameObjects and world data across a networking session to multiple players simultaneously, enabling a focus on gameplay rather than low-level protocols.
Overview of Multiplayer Play Mode
mainMultiplayer 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
Overview of Multiplayer serialization support
mainThe 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
FixedStringtypes. - Custom Types: Implementation of the
INetworkSerializableinterface for manual control. - High-Performance Serialization: Implementation of the
INetworkSerializeByMemcpyinterface for memory-copy based serialization. - Component Serialization: Specialized serialization for
NetworkObjectandNetworkBehaviourcomponents.
Summary of latency issues and solutions
mainWhen designing multiplayer games, latency affects three core pillars. Use the following mapping to choose your architectural approach:
Issue to solve How to solve it Security Server authority Responsiveness Prediction, action casting, client authority Accuracy/consistency Server 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 |Main features of Transport 2.0
mainTransport 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.loggingpackage is installed, logs are routed through its default logger instead ofUnityEngine.Debug.
Access Unity Multiplayer documentation
mainThis repository is archived. For current and actionable Unity multiplayer documentation, use the following official resources:
- General Multiplayer Manual: Unity Manual
- Netcode for GameObjects: Package Documentation
- Unity Transport: Package Documentation
- Multiplayer Tools: Package Documentation
- Multiplayer Play Mode: Package Documentation
New features in the Lobby service
mainThe 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
CreateorUpdateLobbyAPIs 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.
Legacy ClientRpc usage in Netcode for GameObjects
main:::warning
ClientRpcandServerRpcare 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
ClientRpcallows 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.Use ServerRpc for legacy Netcode for GameObjects
main:::warning
ClientRpcandServerRpcare 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
ServerRpcallows 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.Main features of Unity Transport 2.0
mainUnity 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.loggingpackage is installed, Transport logs are routed through its default logger instead ofUnityEngine.Debug.
Using Network Scene Visualization (NetSceneVis)
mainNetwork 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.
Test multiplayer instances with Play Mode Scenarios
mainUse 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.