Problem with overwrite score at Steam Leaderboard

I want to use the steam leaderboard. But it seems like only when I make new leaderboard, I can only write to it one time? Why is that?

Here is the code for calling the upload score

using UnityEngine;
using Steamworks;
using System.Collections;
using System.Threading;
public class SteamLeaderboard : MonoBehaviour {
    private const string s_leaderboardName = "Highscore";
    private const ELeaderboardUploadScoreMethod s_leaderboardMethod = ELeaderboardUploadScoreMethod.k_ELeaderboardUploadScoreMethodKeepBest;
   


    private static SteamLeaderboard_t s_currentLeaderboard;
    private static bool s_initialized = false;
    private static CallResult<LeaderboardFindResult_t> m_findResult = new CallResult<LeaderboardFindResult_t>();
    private static CallResult<LeaderboardScoreUploaded_t> m_uploadResult = new CallResult<LeaderboardScoreUploaded_t>();
   

    void Start()
    {
       
        if (SteamManager.Initialized)
        {
            Init();
            s_initialized = true;
           
            Invoke("Test123", 5);

        }
       
       
    }

    void Test123()
    {
        UpdateScore(11236); // CHANGE SCORE VALUE HERE <---------------------------------------------
    }
   


    public static void UpdateScore(int score)
    {

        if (!s_initialized)
        {
            UnityEngine.Debug.Log("Can't upload to the leaderboard because isn't loadded yet");
        }
        else
        {
           
            UnityEngine.Debug.Log("uploading score(" + score + ") to steam leaderboard(" + s_leaderboardName + ")");
            SteamAPICall_t hSteamAPICall = SteamUserStats.UploadLeaderboardScore(s_currentLeaderboard, s_leaderboardMethod, score, null, 0);
           
            m_uploadResult.Set(hSteamAPICall, OnLeaderboardUploadResult);
        }
    }

    public static void Init()
    {
        SteamAPICall_t hSteamAPICall = SteamUserStats.FindLeaderboard(s_leaderboardName);
        m_findResult.Set(hSteamAPICall, OnLeaderboardFindResult);
        InitTimer();
    }

    static private void OnLeaderboardFindResult(LeaderboardFindResult_t pCallback, bool failure)
    {
        UnityEngine.Debug.Log("STEAM LEADERBOARDS: Found - " + pCallback.m_bLeaderboardFound + " leaderboardID - " + pCallback.m_hSteamLeaderboard.m_SteamLeaderboard);
        s_currentLeaderboard = pCallback.m_hSteamLeaderboard;
        s_initialized = true;
    }

    static private void OnLeaderboardUploadResult(LeaderboardScoreUploaded_t pCallback, bool failure)
    {
        UnityEngine.Debug.Log("STEAM LEADERBOARDS: failure - " + failure + " Completed - " + pCallback.m_bSuccess + " NewScore: " + pCallback.m_nGlobalRankNew + " Score " + pCallback.m_nScore + " HasChanged - " + pCallback.m_bScoreChanged);
    }




    private static Timer timer1;
    public static void InitTimer()
    {
        timer1 = new Timer(timer1_Tick, null, 0, 1000);
    }

    private static void timer1_Tick(object state)
    {
        SteamAPI.RunCallbacks();
    }
}

The currently written data is 1337, and no matter I set UploadScore to, it keeps coming with this messages:

What am I doing wrong?

2 Likes

No one?

Don’t know. Don’t develop for steam. What does their docs say? Are you sure there isn’t a call to overwrite a leaderboard score? If you can write to it once, perhaps you have to use a different call or pass another parameter to have it use a different score after it gets the first score.

Use

private const ELeaderboardUploadScoreMethod s_leaderboardMethod = ELeaderboardUploadScoreMethod.k_ELeaderboardUploadScoreMethodForceUpdate;

instead of

private const ELeaderboardUploadScoreMethod s_leaderboardMethod = ELeaderboardUploadScoreMethod.k_ELeaderboardUploadScoreMethodKeepBest;

I had the same problem. Now steam will overwrite the old value with the new one no matter what

3 Likes

meet the same problem, I use forceupdate and compare score by myself

Thank you so so much!

To anyone, who will be searching this: If you try to update score with higher value, make sure your leaderboard is set up to have sort method “Descending”. For example, if old value = 100 and new value = 200. If sort method “Ascending”, API doesn’t update score.

3 Likes

Be careful that there seems to be a bug where if you create a leaderboard with ascending order, and later change it to descending (and/or have it be “trusted” and then clear it), you’ll need to recreate the leaderboard under a different name.

I spent hours trying to figure out why it was not working, trying out different settings combinations, etc, only to find out that it worked perfectly when creating a different leaderboard from scratch.

Also, don’t bother filling in the community name when you create it, you’ll need to edit the leaderboard and re-enter it anyway.

5 Likes

In case anyone also stumbles on this, the above issue of creating an Ascending leader board and then switching it to Descending is still happening. I initial created mine with ascending an wondered why my calls to SteamUserStats.UploadLeaderboardScore kept returning a 0. Once I deleted the leader boards, set them up in the correct order and refreshed it all worked again.

I have a issue with uploading to steam leaderboards, I wonder if it’s the related. Often uploading a score works fine, but sometimes it fails. And from with in the editor debug information tells me the score went in fine and even the position in the leaderboard the score is. Steam just doesn’t seem to have the score entry when looking at the app admin details. Any ideas?

I have the same problem. I know it’s been a while since you posted, but did you find a solution?

Might it be related to this?

“Uploading scores to Steam is rate limited to 10 uploads per 10 minutes and you may only have one outstanding call to this function at a time.”

https://partner.steamgames.com/doc/api/ISteamUserStats#UploadLeaderboardScore

1 Like