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 Fetching the Last Player Score in Each Tier in Unity Leaderboards

Discussion in 'Leaderboards' started by negital, Jun 3, 2023.

  1. negital

    negital

    Joined:
    Oct 28, 2022
    Posts:
    3
    Hi,

    I am currently developing a feature in my game where I need to present to each player the minimum score required to reach the next tier. The tiers in my game are based on percentiles, so for example, if the last player in tier 4 has a score of 500 points, I would like to make each player in tier 5 aware of this threshold.

    However, from my understanding of the Unity documentation, it seems that I am only able to retrieve the first-place score in each tier using the leaderboard system. As I don't know the number of players in each tier, I am unable to use the GetPaginatedScoresByTier method effectively.

    Is there a way to fetch the score of the last player in each tier directly? If not, it seems I would have to paginate through the entire leaderboard each time to find this information, which would not be ideal for performance.

    Any insights or alternative approaches would be greatly appreciated.

    Thanks in advance for your help.
     
  2. devingunity

    devingunity

    Unity Technologies

    Joined:
    May 26, 2021
    Posts:
    35
    Hi there,

    At the moment, the easiest way to do this would probably be as follows:
    1. Make a GetPaginatedScoresByTier request for the tier for which you wish to know the worst score (tier 4 in your example). The pagination information included in the response, in particular the "Total" field, pertains to the tier you requested (as opposed to the overall leaderboard), and so the "Total" is how many players are in that tier.
    2. Make a second request to GetPaginatedScoresByTier, but with Offset=Total-1 (so e.g. if Total was 500, set Offset to 499), and Limit=1 - this will retrieve only the last score of the tier.
    It is unfortunate that you have to make two requests (one to get the Total and then the second to retrieve the last entry), but this should get you the information that you need! This sounds like a great use case for allowing negative pagination (so that you could simply put in Offset=-1 and get the last entry immediately), this is a feature we haven't implemented yet but could look at in future to make these use cases easier!
     
  3. negital

    negital

    Joined:
    Oct 28, 2022
    Posts:
    3
    Thank you for the effective solution. I appreciate your guidance.
    I'm eager to see the addition of negative pagination in the future, as it would further streamline this process.
    Thanks again for your assistance.