Get started
Follow this workflow to create a Unity account, link your project, and install the SDK to get started with Unity Authentication.
Read time 2 minutesLast updated 18 hours ago
To use Authentication, you need to:
- Sign up for UGS.
- Link your dashboard to a Unity Editor project.
- Install the SDK in your game code.
- Initialize the SDK.
Sign up
If you don't have a Unity account, create one and create a new project to sign up for Unity Gaming Services.- Sign into the Unity Dashboard.
- Select Administration in the side panel.
- Select Sign Up in the top banner and follow the instructions.
Link your project
Link your project to a Unity Cloud project in the Unity Editor through a project ID. Follow these steps to get your project ID.- In the Unity Editor menu, select Edit > Project Settings > Services tab.
- If you’re not already signed in with your Unity ID, either create a new Unity ID or sign in.
- To create a new project, select your organization and select Create. To link to an existing project, select I already have a Unity Project ID. Then, select your organization and project from the dropdown, and select Link.
Install the SDK
To install the latest Authentication package for Unity:- In the Unity Editor, open Window > Package Manager.
- In the Package Manager, select the Unity Registry list view.
- Search for Authentication, or locate it in the package list.
- Select the package, then select Install.
Initialize the Unity Services SDK
To implement Unity Authentication in your game, initialize all the Unity Services SDKs included in the project following this code snippet:using System;using Unity.Services.Core;using UnityEngine;public class InitializationExample : MonoBehaviour{ async void Awake() { try { await UnityServices.InitializeAsync(); } catch (Exception e) { Debug.LogException(e); } }}
Register authentication events
To receive updates about the status of your player, register a function to theSignedInSignInFailedSignedOut// Setup authentication event handlers if desiredvoid SetupEvents() { AuthenticationService.Instance.SignedIn += () => { // Shows how to get a playerID Debug.Log($"PlayerID: {AuthenticationService.Instance.PlayerId}"); // Shows how to get an access token Debug.Log($"Access Token: {AuthenticationService.Instance.AccessToken}"); }; AuthenticationService.Instance.SignInFailed += (err) => { Debug.LogError(err); }; AuthenticationService.Instance.SignedOut += () => { Debug.Log("Player signed out."); }; AuthenticationService.Instance.Expired += () => { Debug.Log("Player session could not be refreshed and expired."); };}