Problem loading leaderboard scores using Social in Unity4

I’m trying to show scores from one of our leaderboards but I either get only the highest score or none at all even though we have about a dozen scores.

This code returns only the highest score:

Social.LoadScores("HS_Leaderboard_1", scores => {
    if (scores.Length > 0) {
        Debug.Log ("Got " + scores.Length + " scores");
        string myScores = "Leaderboard:\n";
        foreach (IScore score in scores)
            myScores += "\t" + score.userID + " " + score.formattedValue + " " + score.date + "\n";
        Debug.Log (myScores);
    }
    else
        Debug.Log ("No scores loaded");
});

I only see one score in the log so I am assuming that the default query is for a single score.

This code returns no scores:

ILeaderboard leaderboard = Social.CreateLeaderboard();
leaderboard.id = "HS_Leaderboard_1";
leaderboard.LoadScores (result => {                
    Debug.Log("Received " + leaderboard.scores.Length + " scores");
    foreach (IScore score in leaderboard.scores)
        Debug.Log(score);
});

For this one I can see the data from the scores in the log, but just under them it it says “Failed to call instance function SetScores because the no object was provided”.
I get the same result whether I use a local ILeaderboard or a private static one.

Both of these examples are based on those in the documentation.
Is there a step I am missing?

Hi! did you ever figure this out? I’m seeing the same thing ( no scores and an error message about the no object provided )

I ended up using the Prime31 plugin. With just a little bit of glue code it worked right away as a replacement for that part of Social.

I’m seeing exactly the same behaviour here too.

Social.LoadScores() only returns the highest score.

Social.CreateLeaderboard() followed by leaderboard.LoadScores() returns no scores, with the error in the log that Kizik posted.

This is code that works fine in Unity 3.5.7 but not in Unity 4.0.1. Anybody got any ideas?

anybody? Same issues here unity 4.0.1f2

Hi,
do you have bug report number for this issue? I would check how it is progressing…

Well, it’s obviously a bug with the current 4.0 build. So, I popped for the iOS GameCenter plugin from Prime31 (i’ve used their social networking plugin before with great success) and for $70 its well worth it. I was up and running in 15 minutes and my scores were posting, I was getting leaderboard data and it has a great api to customize exactly what you want out of it.

ROCKS. I’m up and running thanks to that plugin!

http://prime31.com/docs#iosGameCenter

hi guys, any luck for this i m trying to find as well in mine i just get the highest one and does not loop through. please let me know if you have resolved this issue tks.

Hi! I have the same issue - for any leaderboard I just get the top score and that is it. please help!

Still not fixed.

Any luck on a fix?

I have same problem . I just use the below code , and it worked.

ILeaderboard leaderboard = Social.CreateLeaderboard();
leaderboard.id = "HS_Leaderboard_1";
leaderboard.LoadScores (result => {               
    Debug.Log("Received " + leaderboard.scores.Length + " scores");
    foreach (IScore score in leaderboard.scores)
        Debug.Log(score);
});
2 Likes

Not sure if everyone is still having this problem but I was able to find a solution!
To make it work you need to create a new local leaderboard, with its leaderboard ID the same as your Game Center leaderboard ID you want to load.

I’m currently unsure of how many scores you can load at once, but I’m testing that now!

Here’s the working code:

var leaderboard : ILeaderboard = Social.CreateLeaderboard();
leaderboard.id = "my_leaderboard_ID";

leaderboard.LoadScores(function(scores) {
        if(leaderboard.scores.Length != 0) {
            Debug.Log("Got " + leaderboard.scores.Length + " scores");
            var myScores : String = "Leaderboards:\n";
           
            for(var s : int = 0; s < leaderboard.scores.length; s++) {
                myScores += "\t" + leaderboard.scores[s].userID + " " + leaderboard.scores[s].formattedValue + " " + leaderboard.scores[s].date + "\n";
            }
           
            Debug.Log(myScores);
        }
        else {
            Debug.Log("No scores loaded!");
        }
    }
);

Hope that helps! :slight_smile:

2 Likes

very cool, works for me!