Documentation

Support

Vivox Unity SDK

Vivox Unity SDK

Sign in to a game

How to sign in a player to Vivox services.
Read time 2 minutesLast updated 2 days ago

After you initialize the Vivox SDK, you can sign a user in to the Vivox instance assigned to your game. The name being used for players will either be the Unity AuthenticationId, or a new GUID, if Unity Authentication is not being used. After initialization, call the
VivoxService.Instance.LoginAsync
method to sign in to Vivox.
  • The optional argument of
    VivoxService.Instance.LoginAsync
    is a LoginOptions struct that can set a display name for the user, enable Text-to-Speech, or load in a blocked user list.
If a display name is set in LoginOptions, this name is visible to all users in channels they join; they receive it as DisplayName within the VivoxParticipant results from
VivoxService.Instance.ParticipantAddedToChannel
or
VivoxService.Instance.ParticipantRemovedFromChannel
.
  • The display name is only valid for the current session and does not persist in the Vivox network.
  • The maximum display name length is 127 bytes.
The following code is an example of how to initiate the sign-in process, setting the DisplayName to "Bob", and enabling Text-to-Speech.
using UnityEngine;using Unity.Services.Vivox;class LogInExample : MonoBehaviour{ . . . async void LoginUserAsync() { // For this example, the VivoxService is initialized. var loginOptions = new LoginOptions() { DisplayName = "Bob", EnableTTS = true }; VivoxService.Instance.LoginAsync(loginOptions) } . . .}
You can subscribe to
VivoxService.Instance.LoggedIn
and
VivoxService.Instance.LoggedOut
in order to get events when LoginAsync has been successfully called.
The following code is an example of how to subscribe to the
VivoxService.Instance.LoggedIn
and
VivoxService.Instance.LoggedOut
events, and how to handle the functions for the different LoginState values:
using UnityEngine;using Unity.Services.Vivox;class LoginPropChangeExample : MonoBehaviour{ . . . VivoxService.Instance.LoggedIn += onLoggedIn; VivoxService.Instance.LoggedOut += onLoggedOut; . . . private void onLoggedIn() { // Operations as needed } private void onLoggedOut() { // Operations as needed }}