Greetings. I’ve discovered from one of my clients from my job that many seem to have trouble getting Steam’s leader boards to update properly via Unreal Blueprint.
If you try to use “Write Leaderboards Integer” Blueprint function right now, it will create the leader board stat but will not actually add any entries and if the stats already exist, it’ll only make blank updates – practically nothing happens.
It seems someone already discovered a solution before I did however given some are still having difficulties today I think it’s best I help shed some light on the solution with this article. So I am going to show how I (and Slimax) managed to fix this and what exactly was wrong.
First and foremost, you will obviously need a Steamworks game, if you don’t have one, this tutorial is completely useless to you. To get your game on Steamworks your game must be greenlit via Steam Greenlight than you must submit your game to Steamworks for approval via the website. I don’t own a game on Greenlight myself but my latest client from my job has one and was kind enough to allow me to use it for demonstration (with necessary censorship).
You will also have to download a custom build from the Unreal Engine GitHub then follow the instructions from there and compile the build in Visual Studio. I am trying to submit the fix to the UE GitHub repository so it will be ready by 4.12 or a quick update on 4.11 so hopefully once that’s done this tutorial will no longer be needed for that version and up.
Once that is taken cared of, go back into Visual Studio and search for “OnlineLeaderboardInterfaceSteam.cpp” and open it. This is where the leaderboard interface data is handled to acquire from and send to Steam whenever your game requires access to the leaderboards.
Go to Line 18.
Notice the “%s_%s” string. From my understanding, this is what seems to prevent the game from updating the leader boards properly. I am not sure if this is the same practice for all other leaderboard interfaces since the BP is universal and its meant to update any leaderboards it is connected to (e.g. Google or Apple leaderboards), however apparently this practice doesn’t work well for Steamworks. So if the stat name was “Time”, it’s practically sending “Time_Time” for some odd reason. To fix this, simply replace it with “%s”. Should look like this:
Move further to Line 289 (might vary on your end) and you will find this code branch via the Tick() function.
Specifically look for this snippet.
bSuccess = SteamUserStatsPtr->SetStat(TCHAR_TO_UTF8(*StatName), OldValue + Value) ? true : false;
It is assuming success by inputting the stats name and value, HOWEVER it is also adding the old value to the new one. This only adds your time to your existing leaderboard entry so if the first time you spent 500 seconds during your first ‘Time’, and you spent 200 during your second ‘Time’, it will update your entry to 520 seconds total. It seems it does not handle math well with the value input when setting stats in the code, hence no entry at all. But I don’t think that’s what one would want with their game’s leader board anyway. If I recall, it was meant for trying to beat others original score; beating the previous record. So what should be done is deny entry until the new entry (Value) exceeds the previous one (OldValue).
if (OldValue < Value)
bSuccess = SteamUserStatsPtr->SetStat(TCHAR_TO_UTF8(*StatName), Value) ? true : false;
Should look more like this:
Finally, compile your build and test it in game. Here’s my layout if you need it.
The leader boards should finally show entries and update the stats properly.
…But if you’re in a hurry and can’t really spend the 20-40 minutes to set this up manually, you can download the file here.
Hope this all helps, meanwhile support us through social media and keep track of our website for more tutorials and other goods.
Establish. Explore. Expand.