기술 자료

Multiplayer Services SDK

Multiplayer Services SDK

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:
  1. Create or find a session.
  2. Authenticate players and validate access.
  3. Establish networking and connection data.
  4. Start gameplay and update session information.
  5. 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
State
that tracks the local client's connection to it:
None
,
Connected
,
Disconnected
, or
Deleted
. The state isn't the same as the session's data or membership. A session keeps its data while a client is
Disconnected
, and the player stays a member until they leave, are removed, or the session is deleted.
The following pages describe each stage of the lifecycle:
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
Type
. 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.
Use
MultiplayerService.Instance.Sessions
to access the sessions the player is currently in on this client, and
GetJoinedSessionIdsAsync
to get every session the player is a member of on the service, including sessions this client isn't connected to.

Access 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

IsPrivate
Hidden. The session doesn't appear in query results and can't be joined with Quick Join.Allowed.The host, through
IHostSession.IsPrivate
.
IsLocked
No player can join.Not allowed. No player can join a locked session by any method.The host, through
IHostSession.IsLocked
.
PasswordUnchanged.
HasPassword
is
true
.
Allowed only if the player provides the password in
JoinSessionOptions.Password
.
The host, through
IHostSession.Password
.
A password must be between 8 and 64 characters. The password is write-only: you can't read it back from a session. Use
HasPassword
to check whether a session requires one.
Use
IsPrivate
for invite-only sessions,
IsLocked
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.

The 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

중요
Starting with Multiplayer Services SDK version 1.2, the default network handler implementation for Netcode for Entities automatically creates client and server worlds if none are available when starting a network connection through sessions.
Older versions of the MPS SDK require you to create your Netcode for Entities client and server worlds before you can create or join a Multiplayer Services session. When you first add the Netcode for Entities package to your project, the default bootstrap automatically creates the client and server worlds at startup.
For more advanced use cases, use a custom network handler to override the default integration with Netcode for Entities.