🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

SteamworksAPI achievements only appear after game close, and not during the game.

Started by
2 comments, last by Zurtan 4 years ago

I have used Steamworks to implement achievements in my Unity game.

It works, but for some kind of a reason the achievements only appear after you close the game.

I mean the little notify pop up in the bottom right corner.

This is basically my code(calling the dll I used to wrap Steamworks C++ with C):

This is inside void Start()

{
            bool success = BridgeAPI_Init();
//            Utility.DisplayDialog("SteamWorks", "SteamAPI_Init" + (success ? " successeded" : " failed"), "Ok", "Cancel");
            Debug.Log("SteamAPI_Init" + (success ? " succeeded" : " failed"));
            dbgMsg = "SteamAPI_Init" + (success ? " succeeded" : " failed");
            if (success)
            {
                if (BridgeAPI_RequestCurrentStats())
                {
                    dbgMsg = "RequestCurrentStats succeeded";
                    achievmentsEnable = true;
                }
                else
                    dbgMsg = "RequestCurrentStats failed";
                IntPtr unmanagedPointer = Marshal.AllocHGlobal(BridgeAPI_MaxStrLen());
                ListUnlockedAchievments(unmanagedPointer);
                dbgMsg = Marshal.PtrToStringAnsi(unmanagedPointer);
                Marshal.FreeHGlobal(unmanagedPointer);
            }
        }

Then in FixedUpdate I call this:

void FixedUpdate()
    {
        if (!achievmentsEnable)
            return;
        BridgeAPI_Update();
    }

The C functions I call in C# are implemented like this:

int BridgeAPI_MaxStrLen()
{
    return MaxStringLength;
}

bool BridgeAPI_Init()
{
	return SteamAPI_Init();
}

void BridgeAPI_Shutdown()
{
    SteamAPI_Shutdown();
}

bool BridgeAPI_RequestCurrentStats()
{
	return SteamUserStats()->RequestCurrentStats();
}

bool BridgeAPI_SetAchievement(const char* achievmentName)
{
	return SteamUserStats()->SetAchievement(achievmentName);
}

void BridgeAPI_Update()
{
    SteamAPI_RunCallbacks();
}

Do I need to do anything else during FixedUpdate so the achievements will appear as the player gets them? Instead than in the end after the player close the game?

Advertisement

Sounds like something is cached in the game and synchronized with steam after the API is about to shutdown, so you should read through the docs if there is some call you may have missed

Oh, I actually had to call StoreStats after adding an achievement.

It was confusing documentation wise, but that was what needed to do.

This topic is closed to new replies.

Advertisement