Today, I checked out the Leaderboard Service and integrated it into a test project.
Setting up leaderboards was a breeze. The dashboard and online documentation made it super easy. Honestly, it couldn’t be simpler.
Integrating the code was also straightforward. The C# API for the leaderboards was easy to use too.
I wanted to commend you for creating such a great product.
I did notice a few things during my testing, though.
Firstly, the GetPlayerRangeAsync function throws a “HttpException: (404) HTTP/1.1 404 Not Found” when the player hasn’t added a score yet. It would be more useful if this returned a more specific “PlayerEntryNotFound” exception. That way, I could show a proper “You’re not yet ranked on this leaderboard” message on the UI.
It’s really common for a player to look at a leaderboard where they haven’t submitted a score and toggle common filters like Global, GlobalAroundPlayer, and Friends. So maybe instead of being an exception, it should be a return value that indicates “Player entry not found”.
Secondly, passing a negative offset to the GetScoresAsync method causes a “HttpException: (400) HTTP/1.1 400 Bad Request” exception. It would be more useful if the Leaderboards service clamped the passed value to a valid range.
Finally, when passing an offset that’s greater than the total number of entries, you get an empty list back. While this is expected behavior, it does make it a bit challenging to implement scrolling through the leaderboard. I’d love to see an API that lets me query the total number of entries in a leaderboard. That way, I could see if the player can scroll down further and clamp it to the last leaderboard entry.
Another helpful addition to the Leaderboards Dashboard would be the ability to generate a specific number of test entries. For example, it would be great if we could generate 1000 random entries with scores ranging from 100 to 1000, and fictitious names (not necessarily real playerIDs).
This would allow us to thoroughly test the leaderboard code on the game side, ensuring that it functions properly with a larger set of entries rather than just a small handful.
Thanks a ton for the feedback, we’re glad you’re finding the service easy to use! On the exceptions, as MiTschMR has pointed out this is currently expected behavior, and if you handle the exception in a try/catch block you can use the Reason field to determine the cause of the exception, such as EntryNotFound. That being said we are re-evaluating our patterns for when we should/shouldn’t throw exceptions, so knowing that this was a point of difficulty is helpful!
Custom data and test entries are definitely common feedback points as well, and we’re looking at the best way to support them! No immediate updates on those though I’m afraid, but as and when we have updates we’ll be sure to post them here!
throws compiler error CS0246: The type or namespace name ‘LeaderboardsException’ could not be found (are you missing a using directive or an assembly reference?)
Thanks MiTschMR, but no. Unfortunately. Here are my references in that script:
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEditor;
using Unity.Services.Core;
using Unity.Services.Core.Environments;
using Unity.Services.Authentication;
using Unity.Services.Leaderboards;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
using System.IO;
using System.Diagnostics;
using Newtonsoft.Json;