Use anonymous sign-in

Anonymous sign-in creates a new user for the game session without any input from the player. It's a quick way for a player to get started with your game.

If a player has already signed in before, the SignInAnonymouslyAsync() method recovers the existing credentials of a user whether they signed in anonymously or through a platform account. If there is no user sign-in information, this method creates a new anonymous user.

The following code sample shows how to set up the ability for players to sign into your game anonymously and get an access token.

Copy
async Task SignInAnonymouslyAsync()
{
    try
    {
        await AuthenticationService.Instance.SignInAnonymouslyAsync();
        Debug.Log("Sign in anonymously succeeded!");
        
        // Shows how to get the playerID
        Debug.Log($"PlayerID: {AuthenticationService.Instance.PlayerId}"); 

    }
    catch (AuthenticationException ex)
    {
        // Compare error code to AuthenticationErrorCodes
        // Notify the player with the proper error message
        Debug.LogException(ex);
    }
    catch (RequestFailedException ex)
    {
        // Compare error code to CommonErrorCodes
        // Notify the player with the proper error message
        Debug.LogException(ex);
     }
}