Use anonymous sign-in

Anonymous sign-in creates a new player 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 session token is cached on the SDK, then the SignInAnonymouslyAsync() method recovers the existing credentials of the cached player, regardless whether they signed in anonymously or through a platform account. If there is no player sign-in information, this method creates a new anonymous player.

Note: The anonymous account is not recoverable if it’s not linked to a platform-specific account. For example, the player won’t be able to log in to their anonymous account if they uninstall and then reinstall the game.

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

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);
     }
}

For more information about signing in a cached user, read the Sign In a Cached User section.

After successfully implementing anonymous sign-in, it is recommended to integrate with at least one supported identity providers (link to Identity Providers page) to allow your players to continue their progress from another device or recover their account, should the need arise. In addition, for returning players, refer to Sign in a cached user page for instructions on how to handle their sign-in process.