docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Class SessionObserver

    This class can be used to track events related to an ISession of a specific Type.

    Inheritance
    object
    SessionObserver
    Implements
    IDisposable
    Inherited Members
    object.Equals(object)
    object.Equals(object, object)
    object.GetHashCode()
    object.GetType()
    object.MemberwiseClone()
    object.ReferenceEquals(object, object)
    object.ToString()
    Namespace: Unity.Services.Multiplayer
    Assembly: Unity.Services.Multiplayer.dll
    Syntax
    public class SessionObserver : IDisposable
    Remarks

    Use this class to get events when a session is created, pending creation or failed to be created for a specific session type.
    It is possible to create this class independently of the Unity.Services.Core.UnityServices being initialized, allowing independent system in a project to track session related events without handling the Unity.Services.Core.UnityServices and MultiplayerService states themselves.

    Constructors

    SessionObserver(string)

    Creates a new SessionObserver instance that will track the creation of a session of the given sessionType.

    Declaration
    public SessionObserver(string sessionType)
    Parameters
    Type Name Description
    string sessionType

    The Type to track.

    SessionObserver(string, IUnityServices)

    Creates a new SessionObserver instance that will track the creation of a session of the given sessionType.

    Declaration
    public SessionObserver(string sessionType, IUnityServices registry)
    Parameters
    Type Name Description
    string sessionType

    The Type to track.

    IUnityServices registry

    Optional parameter to specify a custom Unity.Services.Core.IUnityServices to register to.

    See Also
    CreateServices()

    Fields

    SessionType

    The session type tracked by this observer.

    Declaration
    public readonly string SessionType
    Field Value
    Type Description
    string

    Properties

    Session

    Returns the current ISession with a matching SessionType if it exists.

    Declaration
    public ISession Session { get; }
    Property Value
    Type Description
    ISession

    Methods

    Dispose()

    Cleans up all currently registered events tracking the SessionType sessions.

    Declaration
    public void Dispose()

    Events

    AddingSessionFailed

    This event is called when the IMultiplayerService instance fails to create or join a ISession using a Type value equal to SessionType.

    Declaration
    public event Action<AddingSessionOptions, SessionException> AddingSessionFailed
    Event Type
    Type Description
    Action<AddingSessionOptions, SessionException>

    AddingSessionStarted

    This event is called when the IMultiplayerService instance is starting to create or join a ISession using a Type value equal to SessionType.

    Declaration
    public event Action<AddingSessionOptions> AddingSessionStarted
    Event Type
    Type Description
    Action<AddingSessionOptions>

    SessionAdded

    This event is called when a ISession is added successfully with a Type value equal to SessionType.

    Declaration
    public event Action<ISession> SessionAdded
    Event Type
    Type Description
    Action<ISession>

    Implements

    IDisposable
    In This Article
    Back to top
    Copyright © 2025 Unity Technologies — Trademarks and terms of use
    • Legal
    • Privacy Policy
    • Cookie Policy
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)