Steamworks.NET Achievements not working working in Unity

Viewed 15

I'm trying to implement Steam achievements into my game in Unity. The problem is that it worked twice and then suddenly it stopped working. I searched for solutions online and tried this post on the Unity Forum which suggested adding Callbacks, which I did but it still doesn't work.

The class which handles stats and achievements looks like this.

public class SteamCommunityManager : MonoBehaviour
{
    public static SteamCommunityManager instance;

    private bool _isUnlocked = false;

    Callback<UserAchievementStored_t> m_UserAchievementStored;
    Callback<UserStatsStored_t> m_UserStatsStored;

    private void Awake()
    {
        instance = this;
    }

    public void UnlockSteamAchievement(string ID)
    {
        if(!SteamManager.Initialized)
        {
            Debug.Log("SteamManager is not initialized");
            return;
        }

        TestSteamAchievement(ID);
        if (!_isUnlocked)
        {
            m_UserAchievementStored = Callback<UserAchievementStored_t>.Create(OnAchievementStored);
            SteamUserStats.SetAchievement(ID);
            SteamUserStats.StoreStats();
        }
    }

    void OnAchievementStored(UserAchievementStored_t pCallback) 
    {
        Debug.Log(pCallback.m_nGameID);
    }

    public void ModifySteamStats(string ID, int value)
    {
        if (!SteamManager.Initialized)
        {
            Debug.Log("SteamManager is not initialized");
            return;
        }

        int statValue;
        SteamUserStats.GetStat(ID, out statValue);
        statValue += value;
        m_UserStatsStored = Callback<UserStatsStored_t>.Create(OnStatsStored);
        SteamUserStats.SetStat(ID, statValue);
        SteamUserStats.StoreStats();
    }

    void OnStatsStored(UserStatsStored_t pCallback) { }

    public void DEBUG_LockSteamAchievement(string ID)
    {
        if (!SteamManager.Initialized)
        {
            Debug.Log("SteamManager is not initialized");
            return;
        }

        TestSteamAchievement(ID);
        if (_isUnlocked)
        {
            SteamUserStats.ClearAchievement(ID);
        }
    }

    private void TestSteamAchievement(string ID)
    {
        SteamUserStats.GetAchievement(ID, out _isUnlocked);
    }
}

Things I checked:

  • Functions are getting called properly
  • SteamManager is always initialized
  • Achievement already unlocked (Returns true if I have unlocked it, otherwise false)
  • App ID in callback the same as in the text file (Both the same)

Maybe I'm missing something obvious here, but what else can I try to make it work. Thanks in advance.

0 Answers
Related