Unity Player Accounts

Overview

Unity Player Accounts is Unity’s comprehensive sign-in solution that supports persistence across games, devices and platforms. It’s an end-to-end account system that includes a user flow UX, email and password, social sign-in options, and data access and deletion flows.

Unity Player Accounts is integrated with Unity Gaming Services and is one more identity provider that Authentication supports, in addition to Anonymous, Apple, Google, Facebook, Steam, with benefits such as SSO, organization level player pool, and cross-game, cross-device or cross-platform gameplay.

Technical FeatureDescription
Integrated with Unity Gaming Services and EditorPlayer Accounts is the out-of-the-box sign-in and identity solution for Unity Gaming Services and Unity’s ecosystem. It's seamlessly integrated with Authentication and offers additional features such as organization level player identifiers.
Cross-platform and cross-deviceYour players can sign up and sign into your games across a range of platforms, including iOS, Android, Windows, and Mac.
Cross-gameLeverage organization-level player identifiers to maintain persistent player profiles across all of your games.
Streamlined user sign-up & sign-in JourneyYour players have the flexibility to sign up or sign in to their accounts using their preferred method, such as email and password or social accounts like Google or Apple.
Frictionless sign-in experienceTo minimize initial account friction, allow your players to start anonymously and later upgrade to a Player Account without losing any progress. Additionally, single sign-on (SSO) enables players to log in once and access all Player Accounts enabled games without reentering credentials.
Integrate once and forget itOur browser-based sign up and sign-in flow is automatically updated with new features without any integration or update for your game. Focus on building and running your game, without the need to reintegrate your authentication solution. Once integrated, you can rely on Player Accounts to stay up to date with the latest security improvements and features.

Get started

Install the SDK

To install the latest Authentication package for Unity:

  1. In the Unity Editor, open Window > Package Manager.
  2. In the Package Manager, select the Unity Registry list view.
  3. Search for Authentication, or locate it in the package list.
  4. Select the package, then select Install.

For more information, see the Package Manager documentation.

Set up Unity Player Accounts

You can set up Unity Player Accounts directly in the Unity CLoud Dashboard.

Before using Unity Player Accounts, make sure you have the following:

NameDescription
Terms of Service linkYour application’s Terms of Service, which shows a link in the consent step of the sign-in process (first time login) for your application. Note: This link is optional for the initial setup, but you need to provide a Terms of Service link before you go live.
Privacy Policy linkYour application’s Privacy Policy, which presents a link in the consent step of the sign-in process (first time login) for your application. Note: This link is optional for the initial setup, but you need to provide a Privacy Policy link before you go live.
OAuth Client NameThe name of the OAuth client. It’s shown to the user during the consent step, so it should be a recognizable name, such as the integrating application’s name.
PlatformsYour supported platforms. Unity Player Accounts supports iOS/Android and Windows.

Before you publish your game

Review Unity’s compliance and branding guidelines:

  • You must provide a way for players to request data deletion and disclosure requests for your application and their Unity Player Account.
  • Include a link to the Unity Player Accounts account deletion page.
  • Include a link to the Unity Player Accounts privacy support email for data disclosure or other privacy requests.
  • Include a link to the email for data disclosure or other privacy requests.
  • You must always ensure compliance with Unity Terms of Service.
  • You must always maintain, display, and abide by a conspicuously placed Privacy Policy that makes appropriate disclosure to end-users, complies with all applicable privacy and data protection laws and regulations, and grants Unity the necessary rights required for the use of the Unity Player Accounts service.

Term of Service and Privacy

Make sure the Terms of Service and Privacy link are provided in the Unity Cloud Dashboard.

SDK integration

Set up Unity Player Accounts sign-in

After installing the package, in the Editor menu select Services > Authentication > Player Account Settings.

Note: This asset is created under Assets/Resources.

Add the following values, received after onboarding:

  • Client ID
  • Scope (Optional. All or Empty means all permitted scopes)
  • Use Custom Deep Link Uri (Optional. Overrides the default deep link URI)

Note: The authentication flow works without the need for configuring the redirect URI, provided that the registered URIs follow the prescribed format:

  • Desktop/Standalone: http://localhost/callback
  • Android/IOS default deep link URI: unitydl://com.unityplayeraccounts.{unity-project-id}

Unity Player Accounts sample

Note: The sample is built on the standard Unity Input system. Enable Input Manager or Both input systems. In the Unity Editor go to Edit > Project Settings > Player > Other Settings > Active Input Handling.

  • Select Window > Package Manager to import the sample. Look for Authentication and select Import under Samples.

  • Open the sample scene under Assets > Samples > Authentication > [Package-Version] > UI Example > UnityPlayerAccountsUIExample.

Integrate with Unity Authentication Service

Configure a Unity Player Account ID Provider for Unity Authentication:

  1. In the Unity Editor menu, go to Edit > Project Settings..., then select Services > Authentication from the navigation menu.
  2. Select Go to Dashboard to open the Authentication Identity providers web page.
  3. On the web page, select Add Identity Provider and select Unity Player Accounts.
  4. Set up the provider and select Add provider in the pop-up window.
  5. Return to Services > Authentication in the Unity editor and select Refresh. This displays the Unity Player Accounts ID provider.
  6. In the Unity editor, navigate to Services > Authentication > Player Account Settings and ensure the Client ID is correctly set.
  7. Run the package sample scene UnityPlayerAccountsUIExample that you imported earlier.

Note: Subscribing to the SignedIn event is necessary to ensure that your sign-in method is called when the user successfully signs in to their Unity Player account and receives the required access token.

void Awake()
{
   PlayerAccountService.Instance.SignedIn += SignInWithUnity;
}

Sign in a returning player or create new player

Use the SignInWithUnityAsync method to either:

  • Create a new Unity Authentication player with the Unity Player Accounts credentials.
  • Sign in an existing player using the Unity Player Accounts credentials.
async Task SignInWithUnityAsync(string accessToken)
        {
            try
            {
                await AuthenticationService.Instance.SignInWithUnityAsync(accessToken);
                Debug.Log("SignIn is successful.");
            }
            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);
            }
        }

Update a player from anonymous to a Unity Player Account

After you’ve set up anonymous authentication, if the player wants to upgrade from being anonymous to creating a Unity Player Account and sign in, your game should prompt the player to trigger the Unity Player Accounts sign-in and get the Access token from Unity Player Accounts. Then, call the LinkWithUnityAsync API to link the player to the Unity Player Account Access token.

If a cached player exists on the SDK, you can link the cached player to the Unity Player Account.

  1. Sign into the cached player's account using SignInAnonymouslyAsync.
  2. Link the cached player's account to the Unity Player account with LinkWithUnityAsync.

For more information about cached players, refer to Sign In a Cached User.

async Task LinkWithUnityAsync(string accessToken)
        {
            try
            {
                await AuthenticationService.Instance.LinkWithUnityAsync(accessToken);
                Debug.Log("Link is successful.");
            }
            catch (AuthenticationException ex) when (ex.ErrorCode == AuthenticationErrorCodes.AccountAlreadyLinked)
            {
                // Prompt the player with an error message.
                Debug.LogError("This user is already linked with another account. Log in instead.");
            }

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

Use the UnlinkUnityAsync API so your players can unlink their Unity Player account. Once unlinked, if their account isn’t linked to any additional identity, it transitions to an anonymous account.

async Task UnlinkUnityAsync(string idToken)
{
   try
   {
       await AuthenticationService.Instance.UnlinkUnityAsync(idToken);
       Debug.Log("Unlink is successful.");
   }
   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);
   }
}