CoherenceCloudLogin
The CoherenceCloudLogin component provides a no-code solution for logging in to coherence Cloud.

Login Method
You can pick the login method the component should use from the Login dropdown menu.

The component supports all the same login methods as the CoherenceCloud API:
Guest
The easiest way to log in to coherence Cloud is to set Login to As Guest.

This configures the component to log players in to coherence Cloud using a guest account.
When a player logs in to a project for the first time, a new guest id will be generated for them automatically. The guest id is cached locally on the player's device and used to log them in again to the same guest account when they relaunch the application.
It is important to know that uninstalling the application will also wipe out the data for the guest account, and players will no longer be able to access it even if they install it again.
Cloud Unique Id
The Cloud Unique Id field can be used to provide a custom locally unique identifier for the guest account that will be created.
Cloud Unique Ids can be used to log into multiple different guest player accounts on the same device. This might be useful for local multiplayer games, to give each player access to their own guest player account.

Password

The With Password login method can be used to log in to coherence Cloud with a username and a password.
If Auto-Signup is enabled, a new Player Account with the provided username and password will be automatically created, if one does not exist already.
Steam

The With Steam login method can be used to log in to coherence Cloud with a Steam account.
To do so, you have to at least add an authentication ticket for the Steam User that you want to log in as to the Ticket field. You can get the ticket from the SteamUser.GetAuthTicketForWebApi.
If you passed an identity string to the SteamUser.GetAuthTicketForWebApi method, you also need to configure the Identity field to match it.
Epic Games

The With Epic Games login method can be used to log in to coherence Cloud with an Epic Games account.
One-Time Code

The With One-Time Code login method can be used to log in to coherence Cloud with a temporary code acquired using PlayerAccount.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}.");
}
}
There are two use cases for one-time codes:
Transferring progress from one device to another.
Recovering access to a lost account.
One-time codes expire after a certain time and can only be used once.
JWT

The With JWT login method can be used to log in to coherence Cloud with a custom JSON Web Token.
PlayStation
The With PlayStation login method can be used to log in to coherence Cloud with a PlayStation Network account.
Xbox
The With Xbox login method can be used to log in to coherence Cloud with an Xbox account.
Nintendo
The With Nintendo login method can be used to log in to coherence Cloud with a Nintendo Services account.
Input Methods
You can use the Inspector to configure the credentials that should be used when logging in using the selected login method.
If you pick the String input method, you'll be able to provide the credentials directly using the Inspector. This can be useful for testing purposes while developing the game:

You can also pick another input method using the dropdown to support players providing their own credentials at runtime. Three input methods are support in addition to raw strings at this time: ScriptableObject assets, UI Toolkit Text Fields and TextMesh Pro Input Fields.

Log In On Load

If the Log In On Load option is enabled, the component will automatically start logging in to coherence Cloud when it is loaded.
If the option is disabled, then the login process can be started manually by executing the LogInAsync method.
Log In Simulators

If the Log In Simulators option is enabled, simulators will be logged in using the simulator session token that has been provided as a command line argument.
Other Login configuration is ignored in simulator builds.
Accessing the Player Account
If your scenes contain a single CoherenceCloudLogin component with Log In On Load enabled, you can acquire the PlayerAccount it logs into anywhere using PlayerAccount.GetMainAsync.
using Coherence.Cloud;
using UnityEngine;
public class MainPlayerAccountExample : MonoBehaviour
{
async void Start()
{
PlayerAccount playerAccount = await PlayerAccount.GetMainAsync();
var services = playerAccount.Services;
Debug.Log($"Ready to use {services} of {playerAccount}.");
}
}
It is also possible to use multiple CoherenceCloudLogin components to log into multiple separate PlayerAccounts simultaneously on the same device. This might be useful in a game that supports local multiplayer.
You can acquire the PlayerAccount that a particular CoherenceCloudLogin component logs into using LogInAsync. After IsLoggedIn has become true, it can also be acquired using the PlayerAccount property.
using Coherence.Cloud;
using Coherence.Toolkit;
using UnityEngine;
public class CoherenceCloudLoginPlayerAccountExample : MonoBehaviour
{
[SerializeField] CoherenceCloudLogin cloudLogin;
async void Start()
{
PlayerAccount playerAccount = await cloudLogin.LogInAsync();
var services = playerAccount.Services;
Debug.Log($"Ready to use {services} of {playerAccount}.");
}
}
Unity Events
The CoherenceLogin component offers a couple of Unity Events in its Inspector where you can hook your custom game logic:

OnLoggedIn
Event that is raised when the component has successfully logged in to coherence Cloud.
OnLoginFailed
Event that is raised when the component has failed to log in to coherence Cloud.
Last updated
Was this helpful?