文档

Multiplayer Services SDK

Multiplayer Services SDK

Session properties

Understand the data stored in a session, which fields are managed by the SDK, and which fields you set as the host or application.
阅读时间4 分钟最后更新于 1 天前

A session contains built-in fields that the SDK manages and custom fields that the host or service stores as session properties.

Session data

The following table describes the built-in session data fields exposed by the Multiplayer Services SDK. Some values are set when the session is created, some are updated as players join or leave, and some are managed automatically by the SDK.

Field

Description

Set by hostㅤ

Set by service

Notes

Id
The unique identifier of the session.✓✓Generated by the SDK when the session is created or assigned by the user when using
CreateOrJoin
.
Code
The join code players use to enter the session.✗✓Generated by the SDK during session creation.
Name
The user-facing or game-facing name of the session.✓✓Set when the session is created or configured by the host or application.
Type
The session type used to distinguish different session contexts and reconnect flows.✓✗Defined by the user or application when the session is created.
Host
The player ID of the player currently holding host authority over the session.✓✓Updated by the SDK and the host election flow.
Players
The players currently in the session.✗✓Updated by the SDK as players join and leave.
Properties
Session-level metadata and state that the host or service can read and update.✓✓Custom data is set by the host or application; system-managed values can be maintained by the service.
State
The current lifecycle state of the session.✗✓Updated automatically by the SDK as the session changes state.
MaxPlayers
The maximum number of players allowed in the session.✓✓Set by the session host or service when the session is configured.
PlayerCount
The number of players currently in the session.✗✓Derived automatically from the current member list.
AvailableSlots
The remaining number of player slots available in the session.✗✓Derived automatically from
MaxPlayers
and the current member list.
IsPrivate
Whether the session is hidden from public queries.✓✗Set by the host and can be changed during the session lifetime.
IsLocked
Whether the session prevents additional players from joining.✓✗Controlled by the host or application during session management.
HasPassword
Whether a password is required to join the session.✓✗Set by the host when configuring the session.
Network
The connection information and lifecycle state used for the networking setup.✓✓The host configures the network type; the SDK manages the runtime connection data.

Built-in fields versus custom session properties

The session model includes both built-in data and custom property data.
Built-in fields such as
Id
,
Code
,
Host
,
Players
,
State
, and
Network
are managed by the SDK as the session evolves. These fields are central to session lifecycle, matchmaking, and connection setup.
Custom session properties are application-defined metadata you store on the session. These properties are useful for session state, game configuration, matchmaking flags, and match-specific values. The host manages them using
SetProperty
and then persists them with
SavePropertiesAsync
.
Refer to Manage properties as a host for details on how to use these properties.

Session identifiers

A session has three identifiers. Each one has a different purpose:

Identifier

Set by

Purpose

Id
The service, or you when you call
CreateOrJoinSessionAsync(sessionId, options)
.
Uniquely identifies the session. Use it to join from a query result, to reconnect, and to look up joined sessions.
Code
Always generated by the service.A short, human-friendly join code that players share to invite others. Use it with
JoinSessionByCodeAsync
.
Type
You, through
SessionOptions.Type
or
JoinSessionOptions.Type
. If you don't set it, the SDK generates a random value.
A client-side key that identifies the role a session plays in your game, such as
"party"
or
"match"
. The service doesn't store it.
Type
has the following uses:
  • MultiplayerService.Instance.Sessions
    is a dictionary keyed by
    Type
    .
  • SessionObserver
    tracks sessions of a specific
    Type
    .
  • A player can only be in one session of a given
    Type
    at a time on a client.
  • Reconnecting to a session under the same
    Type
    requires you to know its original
    Type
    .
注意
The Multiplayer Services SDK doesn't save the mapping between a session's
Id
and its
Type
. If you set a
Type
and want to support reconnection, save the mapping yourself, for example in
PlayerPrefs
or Cloud Save.

Additional resources