Search Unity

Feedback My Feedback on the Leaderboard Service

Discussion in 'Leaderboards' started by Peter77, Apr 27, 2023.

  1. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,609
    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.
     
    Last edited: Apr 28, 2023
  2. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,609
    Oh, one more thing I forgot to mention - it would be really helpful if I could attach custom data to AddPlayerScoreAsync.
     
  3. MiTschMR

    MiTschMR

    Joined:
    Aug 28, 2018
    Posts:
    487
    It is in fact mentioned here: https://docs.unity.com/leaderboards/en/manual/get-top-score

    Though I am not sure about the whole bucketed thing, but with a try/catch for the LeaderboardException it should return this error value.
     
    Peter77 likes this.
  4. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,609
    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.
     
    Unifikation likes this.
  5. devingunity

    devingunity

    Unity Technologies

    Joined:
    May 26, 2021
    Posts:
    33
    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!
     
    IainUnity3D and Peter77 like this.
  6. MaxBackcountry

    MaxBackcountry

    Joined:
    Jan 24, 2014
    Posts:
    13
    Hi devingunity,

    l can confirm what Peter77 said: I find the new Leaderboard API a great tool, too!

    However I've got problems catching exceptions. Here's the error log I get when the player hasn't got a leaderboard entry yet:

    HttpException`1: (404) HTTP/1.1 404 Not Found
    Unity.Services.Leaderboards.Internal.Http.ResponseHandler.HandleAsyncResponse (Unity.Services.Leaderboards.Internal.Http.HttpClientResponse response, System.Collections.Generic.Dictionary`2[TKey,TValue] statusCodeToTypeMap) (at ./Library/PackageCache/com.unity.services.leaderboards@dd8c55d0e488/Runtime/com.unity.services.leaderboards.internal/Http/ResponseHandler.cs:122)
    Unity.Services.Leaderboards.Internal.Http.ResponseHandler.HandleAsyncResponse[T] (Unity.Services.Leaderboards.Internal.Http.HttpClientResponse response, System.Collections.Generic.Dictionary`2[TKey,TValue] statusCodeToTypeMap) (at ./Library/PackageCache/com.unity.services.leaderboards@dd8c55d0e488/Runtime/com.unity.services.leaderboards.internal/Http/ResponseHandler.cs:226)
    Unity.Services.Leaderboards.Internal.Apis.Leaderboards.InternalLeaderboardsApiClient.GetLeaderboardPlayerScoreAsync (Unity.Services.Leaderboards.Internal.Leaderboards.GetLeaderboardPlayerScoreRequest request, Unity.Services.Leaderboards.Internal.Configuration operationConfiguration) (at ./Library/PackageCache/com.unity.services.leaderboards@dd8c55d0e488/Runtime/com.unity.services.leaderboards.internal/Apis/InternalLeaderboardsApi.cs:270)
    Unity.Services.Leaderboards.Internal.LeaderboardsServiceInternal+<>c__DisplayClass5_0.<GetPlayerScoreAsync>g__GetPlayerScoreInternal|0 () (at ./Library/PackageCache/com.unity.services.leaderboards@dd8c55d0e488/Runtime/com.unity.services.leaderboards.internal/LeaderboardsServiceInternal.cs:66)
    Unity.Services.Leaderboards.Internal.LeaderboardsServiceInternal.RunWithErrorHandling (System.Func`1[TResult] method) (at ./Library/PackageCache/com.unity.services.leaderboards@dd8c55d0e488/Runtime/com.unity.services.leaderboards.internal/LeaderboardsServiceInternal.cs:213)
    Rethrow as LeaderboardsException: Leaderboard entry could not be found
    [...]

    However, I cannot catch this "LeaderboardsException". This code:


    catch (LeaderboardsException ex)
    {
    Debug.LogException(ex);
    }

    throws compiler error CS0246: The type or namespace name 'LeaderboardsException' could not be found (are you missing a using directive or an assembly reference?)

    What am I missing? Thanks a lot!
     
  7. MiTschMR

    MiTschMR

    Joined:
    Aug 28, 2018
    Posts:
    487
    You are probably missing a reference to the Unity.Services.Core assembly, which contains all the exception classes.
     
  8. MaxBackcountry

    MaxBackcountry

    Joined:
    Jan 24, 2014
    Posts:
    13
    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;
     
  9. MiTschMR

    MiTschMR

    Joined:
    Aug 28, 2018
    Posts:
    487
    Ah sorry, just looked at the code now, it is in the namespace
    Unity.Services.Leaderboards.Exceptions
    .
     
    IainUnity3D and MaxBackcountry like this.
  10. MaxBackcountry

    MaxBackcountry

    Joined:
    Jan 24, 2014
    Posts:
    13
    Cool, that's it. Thanks!