Immerse SDK
Toggle Dark/Light/Auto mode Toggle Dark/Light/Auto mode Toggle Dark/Light/Auto mode Back to homepage

Users

Once connected to the multiplayer session, you will receive the list of connected users. This UserList property is accessibly via the INetworkClient which is available in a static context at ImmerseMultiplayer.Client.

An IUser object contains the user’s name (Name), multiplayer ID (Id) and unique ID on the Immerse platform (PlatformId).

PlatformId is only exposed for very specific use cases where a user needs to be identified across multiple applications. Please use Id wherever possible.

Debug.Log("Users in session: ");
foreach (var user in ImmerseMultiplayer.Client.Users)
{
    Debug.Log(user.Name);
}

Local User

The local user object is made readily accessible through the LocalUser property in INetworkClient, as well as being present in UserList.

Debug.Log("The local user is " + ImmerseMultiplayer.Client.LocalUser.Name);

Find User

If you have the ID of a user, you can retrieve their IUser object using the FindUser method in your INetworkClient

var user = ImmerseMultiplayer.Client.FindUser(userId);

Events

Each time a user connects or disconnects, an event is triggered for that user. These events, OnUserConnected and OnUserDisconnected, are accessible via the INetworkClient.

The example below shows how you can subscribe to the user connection and disconnection events:

using ImmerseSDK.Multiplayer;
using UnityEngine;

ImmerseMultiplayer.Client.OnUserConnected += connectingUser =>
{
   Debug.LogFormat("{0} joined the session!", connectingUser.Name);
};

ImmerseMultiplayer.Client.OnUserDisconnected += disconnectingUser =>
{
   Debug.LogFormat("{0} has disconnected", disconnectingUser.Name);
};