Advertisement

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

Started by May 22, 2020 03:08 PM
2 comments, last by Zurtan 4 years, 5 months 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?

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

Advertisement

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