v1.0.0
Latest
2022.3+

Interface ISession

An interface that can be used by a client to access the information of a session.

Namespace: Unity.Services.Multiplayer
Syntax
public interface ISession

Properties

AvailableSlots

Available slots in the session

Declaration
int AvailableSlots { get; }
Property Value
TypeDescription
System.Int32

Code

The join code of the session.

Declaration
string Code { get; }
Property Value
TypeDescription
System.String
Remarks

Prefer this to ID when player-visible strings are needed. Unlike IDs, join codes are much shorter to type and avoid visually ambiguous characters.

CurrentPlayer

The current player in the session.

Declaration
IPlayer CurrentPlayer { get; }
Property Value
TypeDescription
IPlayer

HasPassword

True if the session has a password, false otherwise

Declaration
bool HasPassword { get; }
Property Value
TypeDescription
System.Boolean

Host

PlayerID of the session host.

Declaration
string Host { get; }
Property Value
TypeDescription
System.String

Id

The ID of the session.

Declaration
string Id { get; }
Property Value
TypeDescription
System.String
Remarks

Unique within a project and environment. Sessions can be joined by Id.

See Also
Unity.Services.Multiplayer.ISessionManager.JoinByIdAsync(System.String,Unity.Services.Multiplayer.JoinSessionOptions)

IsHost

Whether the current player is the host of the session.

Declaration
bool IsHost { get; }
Property Value
TypeDescription
System.Boolean

IsLocked

Whether the session is locked.

Declaration
bool IsLocked { get; }
Property Value
TypeDescription
System.Boolean
Remarks

Locked sessions cannot be joined by anyone.

See Also

IsPrivate

Whether the session is private.

Declaration
bool IsPrivate { get; }
Property Value
TypeDescription
System.Boolean
Remarks

Private sessions or not visible in queries and cannot be joined with quick-join. They can still be joined by ID or by Code.

See Also

MaxPlayers

The total number of players allowed in the session, including the host.

Declaration
int MaxPlayers { get; }
Property Value
TypeDescription
System.Int32
See Also

Name

The Name of the session.

Declaration
string Name { get; }
Property Value
TypeDescription
System.String
Remarks

Does not have to be unique. Sessions can be filtered by name in a query.

See Also

PlayerCount

The player count of the session

Declaration
int PlayerCount { get; }
Property Value
TypeDescription
System.Int32

Players

The list of players in the session

Declaration
IReadOnlyList<IReadOnlyPlayer> Players { get; }
Property Value
TypeDescription
System.Collections.Generic.IReadOnlyList<IReadOnlyPlayer>

Properties

The properties of the session.

Declaration
IReadOnlyDictionary<string, SessionProperty> Properties { get; }
Property Value
TypeDescription
System.Collections.Generic.IReadOnlyDictionary<System.String, SessionProperty>

State

The current state of the session.

Declaration
SessionState State { get; }
Property Value
TypeDescription
SessionState

Type

The type is a client-side key used to uniquely identify a session.

Declaration
string Type { get; }
Property Value
TypeDescription
System.String

Methods

AsHost()

Returns a read-write handle to the session with host privileges.

Declaration
IHostSession AsHost()
Returns
TypeDescription
IHostSession

A IHostSession with higher privileges.

Exceptions
TypeCondition
SessionException

Throws a Forbidden error when the caller is not the host.

LeaveAsync()

Leaves the session.

Declaration
Task LeaveAsync()
Returns
TypeDescription
System.Threading.Tasks.Task

A task for the operation.

Exceptions
TypeCondition
SessionException

Thrown when called by a non-session-member. The Error property will be set to InvalidOperation.

ReconnectAsync()

Reconnects to the session.

Declaration
Task ReconnectAsync()
Returns
TypeDescription
System.Threading.Tasks.Task

A task for the operation.

Remarks

Reconnecting is necessary when a player has momentarily disconnected from the network but didn't gracefully leave the session.

Exceptions
TypeCondition
SessionException

Throws a SessionDeleted error when the session is already deleted.

RefreshAsync()

Refreshes the session data.

Declaration
Task RefreshAsync()
Returns
TypeDescription
System.Threading.Tasks.Task

A task for the operation.

Exceptions
TypeCondition
SessionException

Throws a SessionDeleted error when the session is already deleted.

SaveCurrentPlayerDataAsync()

Save changes to the current player.

Declaration
Task SaveCurrentPlayerDataAsync()
Returns
TypeDescription
System.Threading.Tasks.Task

A System.Threading.Tasks.Task representing the asynchronous operation.

Events

Changed

Event that is invoked when the session changes.

Declaration
event Action Changed
Event Type
TypeDescription
System.Action

Deleted

Event that is invoked when the session is deleted.

Declaration
event Action Deleted
Event Type
TypeDescription
System.Action

PlayerJoined

Event that is invoked when a player joins the session.

Declaration
event Action<string> PlayerJoined
Event Type
TypeDescription
System.Action<System.String>
Remarks

The System.String parameter represents the ID of the player who joined.

PlayerLeft

Event that is invoked when a player leaves the session.

Declaration
event Action<string> PlayerLeft
Event Type
TypeDescription
System.Action<System.String>
Remarks

The System.String parameter represents the ID of the player who left.

PlayerPropertiesChanged

Event that is invoked when player properties are changed.

Declaration
event Action PlayerPropertiesChanged
Event Type
TypeDescription
System.Action

RemovedFromSession

Event that is invoked when the current player is removed from the session.

Declaration
event Action RemovedFromSession
Event Type
TypeDescription
System.Action

SessionPropertiesChanged

Event that is invoked when session properties are changed.

Declaration
event Action SessionPropertiesChanged
Event Type
TypeDescription
System.Action

StateChanged

Event that is invoked when the session state changes.

Declaration
event Action<SessionState> StateChanged
Event Type
TypeDescription
System.Action<SessionState>
Remarks

The SessionState parameter represents the new state of the session.

Extension Methods