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?