Course contentsShow
← Unity Game Development
Lesson 826 of 82812. Multiplayer and DeploymentFree lesson

Handling User Authentication and Account Linking

Learners will integrate cross-platform authentication services to allow players to maintain progress and identity across multiple devices and storefronts.

In this lesson, you will learn how to unify a player’s identity across multiple platforms and devices by linking disparate authentication providers to a single Unity Gaming Services (UGS) Player ID.

The Problem of Fragmented Identity

When a player signs in via Google Play on an Android device and then later switches to Steam on PC, they are often treated as two distinct users by default. Without account linking, their game progress, inventory, and social stats remain trapped on the original platform. To solve this, we use the AuthenticationService to "link" a new external identity to the player’s existing anonymous or primary profile.

Implementing Identity Linking

The core concept is to establish a primary "Identity" (usually an anonymous guest ID generated on the first launch) and then associate a platform-specific credential with that account.

If a user decides to link their Steam account to their existing mobile progression, you perform an LinkWithSteamAsync call. This merges the platform’s identity provider (IdP) token into the current session. Once linked, the service recognizes the player as the same entity regardless of whether they sign in via the mobile guest account or their linked Steam account.

async Task LinkPlayerAccount(string steamTicket)
{
    try
    {
        // Link the current authenticated session to a Steam account
        await AuthenticationService.Instance.LinkWithSteamAsync(steamTicket);
        Debug.Log("Account successfully linked to Steam.");
    }
    catch (AuthenticationException ex)
    {
        // Handle common errors like the account already being linked elsewhere
        Debug.LogError($"Linking failed: {ex.Message}");
    }
}

Best Practices for Cross-Platform Persistence

  1. Prioritize Guest Accounts: Allow players to start playing anonymously first. Prompt them to link a "permanent" account (like Steam, Google, or Apple) only when they have meaningful progress to save.
  2. Conflict Resolution: If a player tries to link a Steam account that is already associated with another UGS ID, your game must prompt them to choose which account to keep, preventing accidental data loss or account overwriting.
  3. Session Consistency: After a successful link, ensure the local session is refreshed so that your PlayerId remains consistent throughout the remainder of the session.

Key Takeaway: By linking external platform credentials to a single UGS Player ID, you allow players to maintain a unified identity, ensuring their progression and social data persist seamlessly regardless of the storefront or device they choose.