LogoLogo
HomeOnline DashboardAPIDiscordForums
SDK 1.7 Preview
SDK 1.7 Preview
  • Welcome
  • Overview
    • Features
    • Roadmap
  • Getting started
    • Get the Unity SDK
    • Setup a project
      • 1. Scene setup
      • 2. Prefab setup
      • 3. Test your game locally
        • Local testing using builds
        • Local testing via Unity's Multiplayer Play Mode
        • Local testing via ParrelSync
      • 4. Test in the cloud
        • Deploy a Replication Server
        • Share builds
    • How to... ?
    • Single-player to multiplayer
    • Video tutorials
    • Samples and tutorials
      • Package samples
      • Sample Connection UIs
      • First Steps tutorial
        • 1. Basic syncing
          • 1.1 Animation parameters
          • 1.2 Sending commands
        • 2. Physics / Authority transfer
        • 3. Areas of interest
        • 4. Parenting entities
        • 5. Complex hierarchies
        • 6. Persistence
      • Campfire project
        • Game mechanics
        • Leveraging object pooling
        • Remote interactions: Chairs
        • Remote interactions: Trees
        • A unique object with complex state
        • Custom instantiation and destruction
        • Running a server-side NPC
        • Playing audio and particles
        • A simple text chat
      • Beginner's guide to networking
    • Troubleshooting
  • Manual
    • Unity Components
      • CoherenceSync
      • CoherenceBridge
      • CoherenceLiveQuery
      • CoherenceTagQuery
      • CoherenceGlobalQuery
      • CoherenceInput
      • CoherenceNode
      • PrefabSyncGroup
      • Order of execution
    • Networking state changes
      • Instantiate and Destroy Objects
      • Supported types
      • Messaging with Commands
      • Syncing child GameObjects
      • Animation
      • CoherenceSync references
      • [Sync] and [Command] Attributes
      • [OnValueSynced] Attribute
      • Creating your own syncable member
      • Custom Component Actions
      • Rigid Bodies
      • Interpolation
    • Authority
      • Authority transfer
      • Server-authoritative setup
    • Lifetime
      • Persistence
      • Uniqueness
      • Example: A global counter
    • Parenting network entities
      • Direct children CoherenceSyncs
      • Deeply-nested CoherenceSyncs
      • Nesting Prefabs at Edit time
    • Asset management
      • Instantiating from CoherenceSyncConfig
      • Instantiate via
      • Load via
    • Scene management
    • Multiple Connections within a Game Instance
    • Baking (code generation)
      • Conditional compilation
    • Replication Server
      • Rooms and Worlds
      • Replication Server API
    • Simulators (Servers)
      • Scripting: Client vs Simulator
      • Run local Simulators
      • World Simulators
      • Room Simulators
      • Advanced Simulator Authority
      • Simulator slugs
      • Build and Deploy
      • Command-line arguments
    • Client Connections
    • Optimization
      • Areas of Interest
      • Level of Detail (LOD)
      • Profiling
      • Simulation Frequency
    • Project Settings
    • Advanced topics
      • Big worlds
        • World Origin Shifting
        • Load balancing
      • Competitive games
        • Simulation Frame
        • Determinism, Prediction and Rollback
      • Team workflows
        • Version Control integration
        • Continuous Integration
      • Schema explained
        • Specification
        • Field settings
        • Archetypes
      • Code stripping
      • Replication Server CLI
      • Single-player gameplay
    • Scripting API
  • Hosting
    • Choosing where to host
    • coherence Cloud
      • Online Dashboard
      • Manage Worlds
      • Configure Rooms
      • Player Accounts
      • Game Services
        • Lobbies
        • Cloud Storage
        • Key-Value Store (Legacy)
      • APIs
        • Worlds
        • Rooms
        • Lobbies
        • Cloud Storage
        • Key-Value Store (Legacy)
    • Peer-to-peer
      • Implementing Client hosting
        • Steam Relay
        • Epic Online Services (EOS) Relay
        • Azure PlayFab Relay
  • Support
    • Release notes
    • Glossary
    • Unreal Engine support
    • WebGL support
    • ECS / DOTS support
    • Known issues
    • Upgrade guide
      • Upgrade 1.6 -> 1.7
      • Upgrade 1.5 -> 1.6
      • Upgrade 1.4 -> 1.5
      • Upgrade 1.3 -> 1.4
      • Upgrade 1.2 -> 1.3
      • Upgrade 1.1 -> 1.2
      • Upgrade 1.0 -> 1.1
      • Upgrade 0.10 -> 1.0
      • Upgrade 0.9 -> 0.10
    • Credit cost & pricing
    • Report a bug
Powered by GitBook
On this page
  • CoherenceBridge
  • Auto Login As Guest
  • Main Player Account
  • None
  • PlayerAccount
  • Login As Guest
  • Login With Password
  • Login With Session Token
  • Login With Steam
  • Login With Epic Games
  • Login With PlayStation
  • Login With Xbox
  • Login With Nintendo
  • Login With JWT
  • Login With One-Time Code
  • Linking
  • Unlinking
  • Account Information
  • Username and Password
  • Display Name and Image
  • Email
  • Player Account Id

Was this helpful?

Export as PDF
  1. Hosting
  2. coherence Cloud

Player Accounts

Log players in to coherence Cloud

Was this helpful?

Player Accounts can be used to authenticate players, uniquely identify them across multiple devices, and give them access to .

The provides many ways to authenticate your players with :

CoherenceBridge

CoherenceBridge's Inspector contains a coherence Cloud section that can be used to configure if and how the bridge should connect to the coherence Cloud.

When a CoherenceBridge has been connected with a Player Account, and the Player Account has joined a , the bridge will automatically join a play session started by the lobby's owner.

Auto Login As Guest

This will result in a guest player account logging in to coherence Cloud automatically when the CoherenceBridge is loaded. The player account will remain logged in until the CoherenceBridge is destroyed.

Guest IDs are stored locally on the device, so it is important to know that uninstalling the game will also wipe out the data for the guest account, and players will no longer be able to access it even if they install the game again.

Main Player Account

Setting Player Account to Main causes the CoherenceBridge to connect to coherence Cloud as the Main Player Account.

When you log in to the coherence Cloud via the CoherenceCloud API, using any authentication method you want, it will result in a Main Player Account being created. Once the Player Account has successfully logged in, the CoherenceBridge will automatically connect to the coherence Cloud using this Player Account.

None

If Player Account is set to None, then the CoherenceBridge will not connect to the coherence Cloud automatically.

You can also connect a bridge with a Player Account manually by assigning the Player Account's Services to the the bridge's CloudService property:

using Coherence.Cloud;
using Coherence.Toolkit;
using UnityEngine;

public class ConnectBridgeWithPlayerAccountExample : MonoBehaviour
{
    public CoherenceBridge bridge;

    async void Start()
    {
        PlayerAccount playerAccount = await CoherenceCloud.LoginAsGuest();
        bridge.CloudService = playerAccount.Services;
    }
}

PlayerAccount

Login As Guest

You can use CoherenceCloud.LoginAsGuest to log in to coherence Cloud using a guest account that is automatically generated for you.

Guest IDs are stored locally on the device, so it is important to know that uninstalling the game will also wipe out the data for the guest account, and players will no longer be able to access it even if they install the game again.

using Coherence.Cloud;
using UnityEngine;

public class LoginAsGuestExample : MonoBehaviour
{
    public PlayerAccount PlayerAccount { get; private set; }

    async void Start()
    {
        PlayerAccount = await CoherenceCloud.LoginAsGuest();
        Debug.Log($"Logged in as: {PlayerAccount}.");
    }
}

Login With Password

You can use CoherenceCloud.LoginWithPassword to log in to the coherence Cloud using a username and password.

An autoSignup value of true can be passed to the method to automatically create a new coherence Cloud account with the provided username and password, if one does not exist already. The default value of autoSignup is false.

using Coherence.Cloud;
using UnityEngine;

public class LoginWithPasswordExample : MonoBehaviour
{
    [SerializeField] string username;
    [SerializeField] string password;
    [SerializeField] bool autoSignup;

    public PlayerAccount PlayerAccount { get; private set; }

    async void Start()
    {
        PlayerAccount = await CoherenceCloud.LoginWithPassword(username, password, autoSignup);
        Debug.Log($"Logged in as: {PlayerAccount}.");
    }
}

Login With Session Token

You can use CoherenceCloud.LoginWithSessionToken to log in to coherence Cloud using a session token acquired from a previously login operation.

This can be useful to avoid users from having to re-enter their username and password every time they want to log in.

Session tokens will expire after a certain period of time after the last login operation.

using Coherence.Cloud;
using UnityEngine;

public class LoginWithSessionTokenExample : MonoBehaviour
{
    [SerializeField] GameObject loginUi;

    async void Start()
    {
        var sessionToken = SessionToken.Deserialize(PlayerPrefs.GetString("SessionToken", ""));
        if(sessionToken == SessionToken.None)
        {
            Debug.Log("No session token found. Showing login UI...");
            Instantiate(loginUi);
            return;
        }

        var loginOperation = await CoherenceCloud.LoginWithSessionToken(sessionToken);
        if (loginOperation.HasFailed)
        {
            Debug.LogWarning(loginOperation);
            Debug.Log("Logging in using session token failed. The session token may have expired. Showing login UI...");
            Instantiate(loginUi);
            return;
        }

        var playerAccount = loginOperation.Result;
        PlayerPrefs.SetString("SessionToken", SessionToken.Serialize(playerAccount.SessionToken));
        Debug.Log($"Logged in as: {playerAccount}.");
    }
}

Login With Steam

You can use CoherenceCloud.LoginWithSteam to log in to the coherence Cloud using a Steam account.

If you passed an identity string to the SteamUser.GetAuthTicketForWebApi method, you should also pass that same identity to the CoherenceCloud.LoginWithSteam method.

using Coherence.Cloud;
using UnityEngine;

public class LoginWithSteamExample : MonoBehaviour
{
    public async Awaitable<PlayerAccount> Login(string ticket, string identity = null)
    {
        PlayerAccount playerAccount = await CoherenceCloud.LoginWithSteam(ticket, identity);
        Debug.Log($"Logged in as: {playerAccount}.");
        return playerAccount;
    }
}

Login With Epic Games

You can use CoherenceCloud.LoginWithEpicGames to log in to the coherence Cloud using an Epic Games account.

using Coherence.Cloud;
using UnityEngine;

public class LoginWithEpicGamesExample : MonoBehaviour
{
    public async Awaitable<PlayerAccount> Login(string token)
    {
        PlayerAccount playerAccount = await CoherenceCloud.LoginWithEpicGames(token);
        Debug.Log($"Logged in as: {playerAccount}.");
        return playerAccount;
    }
}

Login With PlayStation

You can use CoherenceCloud.LoginWithPlayStation to log in to the coherence Cloud using a PlayStation Network account.

using Coherence.Cloud;
using UnityEngine;

public class LoginWithPlayStationExample : MonoBehaviour
{
    public async Awaitable<PlayerAccount> Login(string token)
    {
        PlayerAccount playerAccount = await CoherenceCloud.LoginWithPlayStation(token);
        Debug.Log($"Logged in as: {playerAccount}.");
        return playerAccount;
    }
}

Login With Xbox

You can use CoherenceCloud.LoginWithXbox to log in to the coherence Cloud using an Xbox account.

using Coherence.Cloud;
using UnityEngine;

public class LoginWithXboxExample : MonoBehaviour
{
    public async Awaitable<PlayerAccount> Login(string token)
    {
        PlayerAccount playerAccount = await CoherenceCloud.LoginWithXbox(token);
        Debug.Log($"Logged in as: {playerAccount}.");
        return playerAccount;
    }
}

Login With Nintendo

You can use CoherenceCloud.LoginWithNintendo to log in to the coherence Cloud using a Nintendo Services account.

using Coherence.Cloud;
using UnityEngine;

public class LoginWithNintendoExample : MonoBehaviour
{
    public async Awaitable<PlayerAccount> Login(string token)
    {
        PlayerAccount playerAccount = await CoherenceCloud.LoginWithNintendo(token);
        Debug.Log($"Logged in as: {playerAccount}.");
        return playerAccount;
    }
}

Login With JWT

You can use CoherenceCloud.LoginWithJwt to log in to the coherence Cloud using a custom JSON Web Token.

using Coherence.Cloud;
using UnityEngine;

public class LoginWithJwtExample : MonoBehaviour
{
    public async Awaitable<PlayerAccount> Login(string token)
    {
        var playerAccount = await CoherenceCloud.LoginWithJwt(token);
        Debug.Log($"Logged in as: {playerAccount}.");
        return playerAccount;
    }
}

Login With One-Time Code

You can use CoherenceCloud.LoginWithOneTimeCode to log in to the coherence Cloud using a temporary code acquired from another device using CoherenceCloud.GetOneTimeCode.

using Coherence.Cloud;
using UnityEngine;

public class AcquireOneTimeCodeExample : MonoBehaviour
{
    async void Start()
    {
        PlayerAccount playerAccount = await CoherenceCloud.LoginAsGuest();
        string oneTimeCode = await playerAccount.GetOneTimeCode();
        Debug.Log($"Login with this code on your other device: {oneTimeCode}.");
    }
}

public class LoginWithOneTimeCodeExample : MonoBehaviour
{
    public async Awaitable<PlayerAccount> LoginWithOneTimeCode(string oneTimeCode)
    {
        var loginOperation = await CoherenceCloud.LoginWithOneTimeCode(oneTimeCode);
        if (loginOperation.HasFailed)
        {
            Debug.LogWarning($"Logging in failed. The code may have already expired.\n{loginOperation}.");
            return null;
        }

        var playerAccount = loginOperation.Result;
        Debug.Log($"Logged in as: {playerAccount}.");
        return playerAccount;
    }
}

Linking

If you want to add multiple authentication methods to the same Player Account, you can do so by first logging in using any of of the authentication methods, and then linking the rest of the authentication methods using the Link methods on the PlayerAccount class.

using Coherence.Cloud;
using UnityEngine;

public class LinkGuestExample : MonoBehaviour
{
    async void Start()
    {
        PlayerAccount mainPlayerAccount = await PlayerAccount.GetMainAsync();

        // Acquire Guest Id from guest account associated with this machine.
        PlayerAccount guestPlayerAccount = await CoherenceCloud.LoginAsGuest();
        GuestId guestId = guestPlayerAccount.GuestId.Value;
        guestPlayerAccount.Logout();

        // Link the guest id to the main account:
        await mainPlayerAccount.LinkGuest(guestId, force: true);
    }
}

The PlayerAccount class provides the following methods for linking authentication methods into an existing Player Account:

  • LinkGuest

  • LinkSteam

  • LinkEpicGames

  • LinkPlayStation

  • LinkXbox

  • LinkNintendo

  • LinkJwt

Unlinking

Each of the Link methods listed above also have a corresponding Unlink method in the PlayerAccount class that can be used to remove an authentication method from the Player Account.

If an authentication method is already linked with one Player Account, and you try to link it with another one, the operation will fail by default. If however you pass a force value of true to a Link method, then the authentication method will automatically be unlinked from any existing Player Accounts it's associated with.

Warning: If an authentication method is unlinked from a Player Account, and the Player Account has no other authentication methods set up, then access to that Player Account will be lost.

Account Information

Username and Password

You can change the username and (optionally) password of a Player Account using PlayerAccount.SetUsername.

You can remove the username and password from a Player Account using PlayerAccount.RemoveUsername.

If the Player Account has no other authentication methods set up besides the username and password, then RemoveUsername will fail by default. If however you pass a force value of true to the method, then the username and password will be removed regardless.

Warning: Access to a Player Account will be lost if the last authentication method is removed from it.

Display Name and Image

You can change the display name and image of a Player Account using PlayerAccount.SetDisplayInformation.

You can remove the display name and image from a Player Account using PlayerAccount.RemoveDisplayInformation.

Email

You can assign an email address to a Player Account using PlayerAccount.SetEmail.

You can remove an email address from a Player Account using PlayerAccount.RemoveEmail.

Player Account Id

PlayerAccount playerAccount = await PlayerAccount.GetMainAsync();
var cloudService = playerAccount.Services.CloudService;

// Create an identifier for a storage object
// that can hold player-specific data
// based on the player's account's identifier:
StorageObjectId storageObjectId = ("PlayerData", playerAccount.Id);

var loadOperation = await cloudService.LoadObjectAsync<PlayerData>(storageObjectId);
if(loadOperation.IsCompletedSuccessfully)
{
    Debug.Log("Loaded player data: " + loadOperation.Result);
}

The quickest way to log in to coherence Cloud is to set Player Account to Auto Login As Guest in a using the Inspector.

Guest Auth Enabled must be ticked in Project Settings on your for this authentication method to be usable.

You can use the to log in to coherence Cloud manually.

Guest Auth Enabled must be ticked in Project Settings on your for this authentication method to be usable.

User / Password Auth Enabled must be ticked in Project Settings on your for this authentication method to be usable.

To do so, you have to provide at least an authentication ticket for the Steam User that you want to log in as. You get it from the .

Steam Auth Enabled must be ticked in Project Settings on your for this authentication method to be usable.

Epic Auth Enabled must be ticked in Project Settings on your for this authentication method to be usable.

PSN Auth Enabled must be ticked in Project Settings on your for this authentication method to be usable.

Xbox Auth Enabled must be ticked in Project Settings on your for this authentication method to be usable.

Nintendo Auth Enabled must be ticked in Project Settings on your for this authentication method to be usable.

JWT Auth Enabled must be ticked in Project Settings on your for this authentication method to be usable.

One-Time Code Auth Enabled must be ticked in Project Settings on your for this authentication method to be usable.

If no password is provided, then the option to will not be available. This might still be useful if the username is used for game purposes only and not as an authentication method.

A globally unique identifier gets generated for every player account that is created. This id can be accessed via .

The id can be useful for storing player-specific data in .

CoherenceBridge
Online Dashboard
PlayerAccount API
Online Dashboard
Online Dashboard
SteamUser.GetAuthTicketForWebApi
Online Dashboard
Online Dashboard
Online Dashboard
Online Dashboard
Online Dashboard
Online Dashboard
Online Dashboard
PlayerAccount.Id
Cloud Storage
all of coherence Cloud's services
CoherenceCloud API
coherence Cloud
lobby
Auto Login As Guest
Login As Guest
Login With Password
Login With Session Token
Login With Steam
Login With PlayStation
Login With Xbox
Login With Nintendo
Login With JWT
Login With One-Time Code
login with password
Auto Login As Guest