question

Blank avatar image
Blank asked

Why is my leaderboard returning nothing, even when containing data? (Unity)

My leaderboard includes leaderboard statistics for two logged in players, yet when I print result.Leaderboard, It returns nothing: It also does not even run through the foreach statement.

public void GetLeaderboard(string LevelName) {
    var request = new GetLeaderboardRequest {
        StatisticName = LevelName + " Leaderboard"
    };
    PlayFabClientAPI.GetLeaderboard(request, OnLeaderboardGet, OnError);
}
void OnLeaderboardGet(GetLeaderboardResult result) {
    string displayBoard = "";
    print(result);
    print(result.Leaderboard);
    foreach (Transform item in rowsParent) {
        Destroy(item.gameObject);
    }
    foreach (var item in result.Leaderboard) {
        print("testprint");
        displayBoard += (item.Position+1) + " " + item.DisplayName + " " + item.StatValue + "/n";
    }
    MapSelectionScript.setData(displayBoard);
}
Player DataLeaderboards and Statistics
1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Blank avatar image Blank commented ·

Ignore lines 11-13, I was trying something and forgot to delete it

0 Likes 0 ·
Blank avatar image
Blank answered

I fixed the code, it works fine now, thank you for responding

The reason my code was not working was because I was saving the leaderboard data into:

StatisticName = LevelName + " Time Leaderboard"
and getting the leaderboard:
StatisticName = LevelName + " Leaderboard"
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Xiao Zha avatar image
Xiao Zha answered

I have tested your code and it works fine. You can try adding some breakpoints in your code to locate the exact error location. And please make sure the Statistic Name is correct and the Leaderboard is not null. In addition, you can also test the API with Postman to check the API response.

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.