Implement Unity’s multiplayer sessions in your project with this Unity Building Block’s pre-made UI elements. Learn what sessions are, how to set them up, how to debug them, and how to connect to Unity’s Netcode packages.
The Multiplayer Session Building Block helps you integrate Unity’s multiplayer sessions into your project to connect players. This Building Block can serve as a starting point for your multiplayer projects, or as a quick integration of sessions throughout development.
This Building Block demonstrates how to do the following:
The Multiplayer sessions Building Block includes example scenesA Scene contains the environments and menus of your game. Think of each unique Scene file as a unique level. In each Scene, you place your environments, obstacles, and decorations, essentially designing and building your game in pieces. More info
See in Glossary, UIToolkit UI assets, and runtime components to create, browse, and join sessions, and debug them with a SessionInfo panel. If you need gameplay synchronization, you can optionally add Netcode using Unity Netcode for GameObjects or Netcode for Entities.
You can validate that the Building Block is installed correctly by opening one of the included example scenes.
You can now interact with the UI elements in the scene to create a new session.
A multiplayer session represents a group of connected players and provides an abstraction layer for managing multiplayer game states, including initial player connections, host election, players joining and leaving, and network connection establishment. Multiplayer sessions don’t facilitate gameplay synchronization, but are compatible with either Netcode for GameObjects or Network for Entities, which can handle authoritative game state replication after players connect. For example, a typical connection flow might look like the following:
The Multiplayer Session Building Block contains the following scenes:
| Scene | Description |
|---|---|
| JoinByBrowsing | Let players browse available sessions to join or create their own new session. Ideal for finding lobbies with specific settings or players. |
| JoinByCode | Let players create a session and share a simple join code that other players can use to join the session. Perfect for joining and inviting players to a specific session through copying a code. |
| QuickJoin | Let players join the first available session. Perfect for quickly joining any existing session when matching with specific rules doesn’t matter. |
| QuickJoinDebug | Similar to QuickJoin but with an additional SessionInfo window with information about the session. Useful for debugging a session. |
SessionBrowser UXML:
CreateSessionElement: Specify a session name and create a session.SessionBrowserElement: Displays the available sessions. Click to select a session.RefreshListButton: Refreshes the list of sessions from the SessionBrowserElement.JoinButton: Join a selected session from the list.
CurrentSession UXML:
SessionNameLabel: Displays the name of the watched session.PlayerCountLabel: Displays the number of players in the watched session.PlayerNameLabel: Displays the player’s own name.CopySessionCodeElement: Displays the join code for the session so it can be copied.PlayerListView: Displays the list of players that have joined the session.LeaveSessionButton: Select to leave the joined session.
JoinSessionByCode UXML:
CreateSessionElement: Specify a session name and create a session.CopySessionCodeElement: Displays the join code for the session so it can be copied.JoinSessionByCode: Enter a session code to join a session.
CurrentSession UXML:
SessionNameLabel: Displays the name of the watched session.PlayerCountLabel: Displays the number of players in the watched session.PlayerNameLabel: Displays the player’s own name.CopySessionCodeElement: Displays the join code for the session so it can be copied.PlayerListView: Displays the list of players that have joined the session.LeaveSessionButton: Select to leave the joined session.
JoinSessionByQuickJoin UXML:
* QuickJoinButton: Join a session with the Quick Join API.
CurrentSession UXML:
* SessionNameLabel: Displays the name of the watched session.
* PlayerCountLabel: Displays the number of players in the watched session.
* PlayerNameLabel: Displays the player’s own name.
* CopySessionCodeElement: Displays the join code for the session so it can be copied.
* PlayerListView: Displays the list of players that have joined the session.
* LeaveSessionButton: Select to leave the joined session.
JoinSessionByQuickJoin UXML:
* QuickJoinButton: Join a session with the Quick Join API.
SessionInfo UXML:
* SessionInfo: Displays debugging information for an active session, similar to the Sessions Viewer.
CurrentSession UXML:
* SessionNameLabel: Displays the name of the watched session.
* PlayerCountLabel: Displays the number of players in the watched session.
* PlayerNameLabel: Displays the player’s own name.
* CopySessionCodeElement: Displays the join code for the session so it can be copied.
* PlayerListView: Displays the list of players that have joined the session.
* LeaveSessionButton: Select to leave the joined session.
Use Multiplayer Play Mode to test the setup with multiple players directly from the Unity Editor.
To integrate either Netcode for GameObjectsThe fundamental object in Unity scenes, which can represent characters, props, scenery, cameras, waypoints, and more. A GameObject’s functionality is defined by the Components attached to it. More info
See in Glossary or Netcode for Entities with your sessions, do the following:
SessionSettings.
SessionSettings ScriptableObject, locate and enable the Create Network Session option, which allows your sessions to be recognized and managed by your chosen Netcode solution.SessionSettings.
SessionSettings to match your intended network architecture. You can choose from the following:
To understand more about the different NetworkTypes, refer to the Network connection management.
VisualElement in your UXML has its SessionType set properly.