Introduction to multiplayer sessions
Learn how multiplayer sessions manage connected players, session ownership, and game state in Unity Multiplayer Services.
읽는 시간 8분최근 업데이트: 7일 전
Sessions provide an abstraction layer for managing connected players, session ownership, and gameplay state across multiplayer experiences. In Unity Multiplayer Services (MPS SDK), a session acts as the shared coordination point for players, host election, data updates, and connection setup.
A session represents a group of connected players and manages their interactions through different connection types, including client-hosted solutions like Relay and Distributed Authority, or dedicated game servers. Sessions work with either the Netcode for GameObjects or the Netcode for Entities networking libraries.
What sessions are
A session is the shared container that coordinates a multiplayer game. It keeps track of connected players, session metadata, and game state, and it exposes the operations needed to create, join, modify, and leave a multiplayer match.
The MPS SDK combines the underlying functionality of Lobby, Matchmaker, and Relay into a single API centered on sessions. This single interface reduces boilerplate code and standardizes UGS usage, automatically managing features like Lobby heartbeating and, when enabled, the Lobby/Relay integration, allowing developers to focus on unique game features.
The following diagram shows the flow for a typical session-based setup from the host's point of view point of view:
How sessions work
Sessions manage the lifecycle of a multiplayer match from creation to shutdown. They can create a lobby, assign a host, manage connection data, and handle player join and leave events as the session evolves.
The session model supports several important concepts:
- Session ownership: One player or service-owned session can act as the authoritative host for a match.
- Player membership: Each connected player is tracked as part of the session and can have per-player state.
- Connection setup: Sessions can use different networking options, depending on the runtime architecture you choose.
- Session data: Session metadata and player properties can change while the match is running.
When a session starts, the MPS SDK can create a lobby, allocate relay resources, and pass the relevant connection data to your networking layer. This reduces the amount of service-specific coordination you need to implement in your game code.
The following diagram shows the flow for a typical session-based setup from the client's point of view point of view:
Session lifecycle and state
A session doesn't exist only as a container for players. It also manages state and behavior across the full match lifecycle. For example, the session can track player joins and departures, keep host ownership up to date, and support reconnection or migration when needed.
The lifecycle commonly includes:
- Create or find a session.
- Authenticate players and validate access.
- Establish networking and connection data.
- Start gameplay and update session information.
- Handle disconnects, host migration, or session cleanup.
This SDK lets you focus on game logic while the session API manages the supporting multiplayer infrastructure.
Each session also reports a that tracks the local client's connection to it: , , , or . The state isn't the same as the session's data or membership. A session keeps its data while a client is , and the player stays a member until they leave, are removed, or the session is deleted.
StateNoneConnectedDisconnectedDeletedDisconnectedThe following pages describe each stage of the lifecycle:
- Creation: Create a session
- Joining: Find and join a session
- Disconnection and reconnection: Reconnect to a session
- Host changes: Migrate session host
- Leaving, including automatic leave when the application quits: Leave a session
- Deletion: Delete a session
For a description of each state and when it changes, refer to Session states.
Session data
Sessions include the information needed to identify the match, track its current members, manage access rules, and connect players to the active network.
For more information, refer to Session properties and the package documentation.
Multiple sessions
A player can be a member of more than one session at the same time, as long as each session has a different . For example, you can keep a persistent party session for a group of friends and join a separate match session for each game they play together.
TypeUse to access the sessions the player is currently in on this client, and to get every session the player is a member of on the service, including sessions this client isn't connected to.
MultiplayerService.Instance.SessionsGetJoinedSessionIdsAsyncAccess rules
Three settings control who can find and join a session. They're independent of each other, and they're often confused:
Setting | Effect on queries and Quick Join | Effect on joining by ID or code | Who can change it |
|---|---|---|---|
| Hidden. The session doesn't appear in query results and can't be joined with Quick Join. | Allowed. | The host, through |
| No player can join. | Not allowed. No player can join a locked session by any method. | The host, through |
| Password | Unchanged. | Allowed only if the player provides the password in | The host, through |
A password must be between 8 and 64 characters. The password is write-only: you can't read it back from a session. Use to check whether a session requires one.
HasPasswordUse for invite-only sessions, to stop new players from joining a session that's already in progress, and a password to restrict access to players who know a shared secret.
IsPrivateIsLockedThe network connection
A session can manage a network connection for its members, such as a Relay allocation, a Distributed Authority connection, or a direct connection, and pass the connection data to your netcode library. The session and its network have separate lifecycles: the host can stop and restart the network without ending the session. For more information, refer to Network connection management.
What a session isn't
A session works with several other concepts, but it isn't any of them:
- A session isn't a lobby. The SDK uses a lobby to store session data, but the session adds player roles, networking, events, and lifecycle management on top of it.
- A session isn't a Relay allocation. A session can create and manage a Relay allocation as its network connection, but the session continues to exist if the network stops.
- A session isn't a netcode connection. Your netcode library, such as Netcode for GameObjects or Netcode for Entities, synchronizes gameplay state. The session tells it how to connect.
- A session isn't persistent storage. Session data is deleted when the session is deleted. Use Cloud Save for data that must outlive a session.
- A session isn't a Matchmaker match. Matchmaker finds players to play together. The SDK then places those players into a session.
When to use sessions
Use sessions when your game needs a shared multiplayer state with consistent player membership and service-managed coordination. Sessions are useful for games that need to do the following:
- Create a match and keep it organized around a single host or service-owned session.
- Let players join and leave without manually reworking lobby or relay setup.
- Share per-session or per-player data during the match.
- Coordinate networking flows between connection, matchmaking, and gameplay logic.
Sessions are especially useful when you want to unify Lobby, Matchmaker, and Relay behavior under one programming model while still retaining access to service-specific APIs when needed.
Additional resources
- Create a session
- Find and join a session
- Match players
- Manage session data
- Monitor and debug sessions
- Connect players through a relay
- Session properties