Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
This question was closed May 24, 2021 at 06:44 AM by SlevinKGames for the following reason:

The question is answered, right answer was accepted

avatar image
1
Question by SlevinKGames · May 22, 2021 at 09:56 AM · google play gamesleaderboardrankingtiming-issue

Google Play Services leaderboard - player rank always 0

Hello,

I have an issue with the Google Play Services Leaderboard and I am stuck for days already.

I am using the Play Games Plugin for Unity https://github.com/playgameservices/play-games-plugin-for-unity.

I am trying to get the Userrank for a specific level. Therefore I am loading the Scores via the LoadScores Function and this seems to work fine.

The issue seems to be, that I get a correct rank in the "LoadScores" Function but the overall GetUserRank Function is still returning rank = 0, no matter what the actual Userrank is.

My guess is that this is a timing issue after all and that the rank is returned before the LoadScores Function has calculated the correct rank to return.

 public int GetUserRank(string levelID)
     {
         int rank = 0;
         string user = PlayGamesPlatform.Instance.localUser.id;
         string leaderboard = ReturnLeaderboard(levelID);
     Social.LoadScores(leaderboard, scores =>
     {
         if (scores.Length > 0)
         {
             Debug.Log("Retrieved " + scores.Length + " scores");
 
                 //Filter the score with the user name
                 for (int i = 0; i < scores.Length; i++)
             {
                 if (user == scores[i].userID)
                 {
                     rank = scores[i].rank;
                         // This prints out the actual rank of the user and seems to work
                         print("Rank in LoadScoresFunction: " + rank);
                     break;
                 }
             }
         }
         else
             Debug.Log("Failed to retrieved score");
     });
     //Here the rank is always 0, no matter the outcome of the LoadScores Function above
     print("Rank in PlayGamesController: " + rank);
     return rank;
 
     }


I reference this function from other scripts via:

 int rank = PlayGamesController.Instance.GetUserRank(levelID);

Any ideas/hints greatly appreciated.

Thanks!

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image SlevinKGames · May 24, 2021 at 06:43 AM 1
Share

If someone stumbles upon this question: The problem seems to be that my function is executed async. I had to work with a callback and a lambda expression to solve this, as someone on stack overflow suggested: https://stackoverflow.com/questions/67657693/unity-problem-with-google-play-services-leaderboard-get-user-rank

0 Replies

  • Sort: 

Follow this Question

Answers Answers and Comments

122 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Google Play Services leaderboard takes time to appear 0 Answers

GPGS Leaderboard returns only the outdated scores (Google Play Game Service) 3 Answers

Need help, Not showing Leaderboard UI for android. 1 Answer

Leaderboard is not displaying any score after tapping on it. I always see only one message "Unbelievable there is no score to display". 0 Answers

How to get Leaderboard Rank 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges