Search code examples
c#unity-game-enginegoogle-play-gamesleaderboard

can't load scores from leaderboard


i'm setting up a leaderboard system in my unity game, using the google play games services plugin.

i want to load score in order to integrate them in my custom LeaderbordUI, I followed the documentation and used the ILeaderboard.LoadScores but it's not working.

when i check the logcat i get this :

02-04 11:03:56.580: W/Unity(18969): !!! [Play Games Plugin DLL] 02/04/19 11:03:56 +01:00 WARNING: Error returned from fetch: -108

I have tried to loadScore with the method "Social.LoadScores" and "PlayGamesPlatform.Instance.LoadScores", but i'm getting the same warning.

PS: when i use Social.ShowLeaderboardUI() it shows me the leaderboard. but when i use PlayGamesPlatform.Instance.ShowLeaderboardUI(LB_Stars.id) to show a specific leaderboard it gives me "hmm,something went wrong in play games"

public void LoadLeaderboard()
{
    LB_Stars.LoadScores(ok =>
    {
        if (ok)
        {
            LoadUsersAndDisplay(LB_Stars);

        }
        else
        {
            Debug.Log("Error retrieving STARS leaderboard");
        }
    });

}

internal void LoadUsersAndDisplay(ILeaderboard lbStar)
{

    Debug.Log("gonna load user and display them");

    List<string> userIds = new List<string>();

    foreach (IScore score in lbStar.scores)
    {
        userIds.Add(score.userID);
    }

    Social.LoadUsers(userIds.ToArray(), (users) =>
    {
        string status = "Leaderboard loading: " + lbStar.title + " count = " +
            lbStar.scores.Length;
        foreach (IScore score in lbStar.scores)
        {
            IUserProfile user = FindUser(users, score.userID);

            if (user != null)
            {

                UserLeaderboardClone = Instantiate(UserLeaderboardPrefab);
                UserLeaderboardClone.name = score.rank.ToString();

                LeaderboardUserScript lbUser = UserLeaderboardClone.GetComponent<LeaderboardUserScript>();
                lbUser.transform.SetParent(LBScrollview.content.transform, false);

                FillUserInfo(lbUser, user, score);

            }
        }
    });
}

Solution

  • Okay i've figured it out, based on a comment on github https://github.com/playgameservices/play-games-plugin-for-unity/issues/2045#issuecomment-350335234