Game ideas & features

Your next feature

Leaderboard

Save the score after each round and show who's ahead.

Requires a player session
Unity
Illustration of Leaderboard
Your visible result

Your test score appears in the leaderboard after a round.

View leaderboard standings3:54
Open video separately ↗

Prepare the same project

  1. Choose the same project in the dashboard as in your game configuration.

    Leaderboard →
  2. Create or reuse these test entries in the dashboard form. These are example values, not current project data.

    Key (slug)
    weekly
    Sort Order
    DESC
    Accept scores only from validated runs
    false
  3. Save, reload and verify the entries before running the example. Preserve unrelated definitions.

Build this feature

You can preview the guide. Running it requires an active project key. Prepare project

SDK installed, project configuration imported and player signed in.

Save the C# file, attach it to a GameObject and enter Play. Check Console.

C#
Assets/Scripts/LeaderboardDemo.cs
horizOn callSetup
1using UnityEngine;
2using PM.horizOn.Cloud.Core;
3using PM.horizOn.Cloud.Manager;
4​
5// Attach this script to a GameObject in your first scene.
6public class LeaderboardDemo : MonoBehaviour
7{
8 async void Start()
9 {
10 // Setup: initialize, connect and sign in a player.
11 HorizonApp.Initialize();
12 await new HorizonServer().Connect();
13 if (!UserManager.Instance.IsSignedIn)
14 {
15 bool authenticated = UserManager.Instance.HasCachedAnonymousToken()
16 ? await UserManager.Instance.RestoreAnonymousSession()
17 : await UserManager.Instance.SignUpAnonymous("StatisticsPlayer");
18 if (!authenticated) return;
19 }
20​
21 // horizOn: submit a score, read the top list and the own rank.
22 var boards = LeaderboardManager.Instance;
23 bool submitted = await boards.SubmitScore(12500, boardKey: "weekly");
24 if (!submitted) { Debug.LogWarning(boards.LastErrorCode); return; }
25 var top = await boards.GetTop(10, useCache: false, boardKey: "weekly");
26 if (top == null) return;
27 foreach (var entry in top) Debug.Log($"#{entry.position} {entry.username}: {entry.score}");
28 var rank = await boards.GetRank(boardKey: "weekly");
29 if (rank != null) Debug.Log($"Your rank: {rank.position}");
30 }
31}
Open the complete SDK sample ↗

Test your new feature.

Your test score appears in the leaderboard after a round.

Choose the same project in the dashboard as in your game configuration.

Endpoints
  • POST/leaderboard/submit
  • GET/leaderboards/{boardKey}/top
  • GET/leaderboards/{boardKey}/rank
  • GET/leaderboards/{boardKey}/around
All endpoints in the API reference