Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only.

    Please, do not make any changes to your username or email addresses at id.unity.com during this transition time.

    It's still possible to reply to existing private message conversations during the migration, but any new replies you post will be missing after the main migration is complete. We'll do our best to migrate these messages in a follow-up step.

    On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live.


    Read our full announcement for more information and let us know if you have any questions.

Question Is there a way to show a user's rank as a percentage?

Discussion in 'Leaderboards' started by DaegeunPark, May 8, 2023.

  1. DaegeunPark

    DaegeunPark

    Joined:
    Jul 28, 2016
    Posts:
    10
    I want to show the user's current rank as a percentage with the formula (user's current rank/all users). Are there APIs that will make this possible?
     
  2. EmilF_Unity

    EmilF_Unity

    Unity Technologies

    Joined:
    Jun 10, 2022
    Posts:
    18
    Hi DragonGalaxy,

    thanks for looking into leaderboards! There is currently no single API for that exact information but the following two calls should do the trick:
    1. First retrieving a page of scores via the
      GetScoresAsync
      method in the SDK or else from the API directly (docs can be found here) will provide the total number of scores (aka the number of users in the leaderboard) as a field on the return object
    2. Then fetching the user's current rank via
      GetPlayerScoreAsync
      in the SDK or the API (docs)
    That would provide the inputs for the percentage formula. If you roughly know where the user currently is on the leaderboard, you might be able to use the limit and offset parameters on the first call to include the user in the returned page and skip the second call.

    Alternatively if the percentage does not need to be exact, you could use percentage-based tiers. For example by creating tiers in 5 or 10% intervals, and then the appropriate tier label will be returned along with the rank when the user score is fetched.

    Hope this helps, and let me know if there are any other questions :)
     
    ertbaran and IainUnity3D like this.
  3. DaegeunPark

    DaegeunPark

    Joined:
    Jul 28, 2016
    Posts:
    10
    GetScores method has a maximum limit of 1000. what if there are 100,000 users recorded on the leaderboard? Is there any way to know the number of users recorded on the leaderboard?
     
  4. EmilF_Unity

    EmilF_Unity

    Unity Technologies

    Joined:
    Jun 10, 2022
    Posts:
    18
    Hi DragonGalaxy,

    there is actually no need to fetch all the scores since the GetScores response object includes a dedicated
    total
    field which provides the total number of scores on the leaderboard. Fetching a single score by specifying the
    ?limit=1
    query parameter would be enough to provide that information.