Get started with Leaderboards
Set up and integrate Leaderboards into your project using the Unity Dashboard, Software Development Kit, CLI, or REST API.
Read time 4 minutesLast updated 21 days ago
The first step in using Leaderboards is to learn how to implement the feature. This section describes how to set up Leaderboards for your project.
Topic | Description |
|---|---|
| Leaderboards in the Unity Dashboard | Learn where to find Leaderboards in the Unity Dashboard. |
| SDK Installation & Setup | Learn how to link your project with a Unity Gaming Services project and install and setup the SDK. |
| Leaderboards in the UGS CLI | Learn how to interact with Leaderboards using the Unity CLI. |
| Leaderboards Authoring | Learn how to deploy Leaderboards configurations from the editor using the Deployment window. |
| Using the Leaderboards REST API | Learn about the available REST API for accessing Leaderboards without the Unity SDK. |
| Using Leaderboards with Cloud Code | Learn how to access Leaderboards using the Cloud Code service. |
Unity Dashboard
You can set up and manage Leaderboards in the Unity Dashboard:- In the Unity Dashboard, select the Products tab from the sidebar.
- Under Community, go to Leaderboards and select Launch.
Unity SDK installation and setup
The Leaderboards SDK requires Unity 2020.3.0 or newer.Install Leaderboards SDK
You can install the package in the Unity Editor. Navigate to Window > Package Manager and select Unity Registry in the Packages dropdown on the top left. You can either:- Search for Leaderboards in the search bar on the top right.
- Add the package by name. Open the dropdown indicated by +, and select "Add package by name...". Search the SDK package ID, "com.unity.services.leaderboards", without its version.
After installation, the Leaderboards SDK is available in Unity scripts from the
Unity.Services.LeaderboardsC#
using Unity.Services.Leaderboards;
Install Authentication SDK
The Leaderboards package relies on the Authentication package. The Unity Authentication service creates an account to persist player scores where you can use anoynymous sign-in or platform-specific authentication. The Authentication package is installed as a dependency when you install the Leaderboards package. For information on installing packages manually, refer to Install a package from a registry. After installation, the Authentication SDK is available in Unity scripts from theUnity.Services.AuthenticationC#
using Unity.Services.Authentication;
Link your Unity project
Once installed, the Authentication package prompts you to link your Unity project to a Unity Gaming Services Project ID. Follow the instructions in the prompt on the screen to link your project. Alternatively, follow the steps to Link your project in the Unity Editor.Initialize the SDKs and authenticate the player
You must initialize the Leaderboards SDK and its dependencies from inside a Unity script lifecycle callback before use. The following example uses theAwakeawait UnityServices.InitializeAsync();Unity.Services.CoreC#
using UnityEngine;using Unity.Services.Core;using Unity.Services.Authentication;public class LeaderboardsSample : MonoBehaviour{ private async void Awake() { await UnityServices.InitializeAsync(); await AuthenticationService.Instance.SignInAnonymouslyAsync(); }}
Next steps
After completing the above steps the Leaderboards SDK is now ready to use from theUnity.Services.LeaderboardsLeaderboards in the UGS CLI
The Unity Gaming Services (UGS) command line interface provides a scalable and automatable alternative to the Unity Dashboard and improves your team's workflows and productivity. The CLI is used to manage, test and deploy your Leaderboards configuration. See the documentation on how to install and use the CLI.Deploy a Leaderboards configuration
To make your Leaderboards configurations accessible to the game client, you must deploy the configuration to the Leaderboards service. Refer to write configuration to learn more about script deployment.Configure the UGS CLI
To get started with the UGS CLI, perform the following steps:- Install the UGS CLI.
-
Configure your Project ID and Environment as such:
ugs config set project-id <your-project-id>
ugs config set environment-name <your-environment-name> - Configure a Service Account with the required roles for Leaderboards and environments management. Refer to Get Authenticated.
Deploy the script
Run the following command:ugs deploy <path-to-configuration-file>Leaderboards REST API
Developers that do not use Unity can access APIs via web endpoints or REST APIs. REST APIs provide more flexibility and allow you to automate your workflows by using your favorite language and game development engine. The Leaderboards service provides the following REST APIs:- Leaderboards Player API for performing player actions, such as submitting or fetching scores.
- Leaderboards Admin API for performing admin actions, such as creating or updating leaderboards, and deleting or resetting scores. It is also used to perform player actions on behalf of a player.