[UE4 Tutorial] Resolving Steam Leaderboards


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.


10 responses to “[UE4 Tutorial] Resolving Steam Leaderboards”

  1. Thanks for this! It doesn’t look like the fix made it into 4.12, unfortunately. Any word on when the fix will be integrated with the engine?

    Like

    • I will see if I can make a pull request and get it into 4.12, but I am honestly still trying to find how to even do that. Working with git is not something I was used to. I’m more of the SVN guy.

      Like

  2. To be honest I doubt they would accept this. It would be best to add extra options to allow decrementing/incrementing or setting the value directly. Also, some people may want to add a negative value and count down.

    Like

    • I will see if I can try to implement those two in as well, but my goal was to simply get the feature itself updating Steamworks properly. I’m still not very pro at Steamworks yet and I was only lucky to get this far because one of my clients granted me access to Steamworks to fix the same issues he struggled with in his game.

      Like

  3. Hi there!

    Thanks a lot for your tutorial. Unfortunately it does not really work for me in UE 4.12.5.

    I’ve changed the lines in OnlineLeaderboardInterfaceSteam.cpp to handle the stat name and values correctly, but it still doesn’t write a int value to the Steam leaderboard. It only creates the leaderboard with the given name, just like in the retail engine 😦

    Do you have any experience with this fix in 4.12?

    Cheers!

    Like

  4. I’m just now starting to look into the steam leaderboards system and will eventually have to get this working for our game as well. But I wanted to point out a few issues with your code: in your FString::Printf you are passing it two parameters but you only have one formatting parameter. You need to remove the other one.

    Regarding the increment/decrement issue it would be best to have the Set value be directly set and then add extra functionality and nodes to handle incrementing and decrementing for instance.

    Like

  5. I’m not very familiar with C++ yet. Since you’ve supplied the .cpp file, does that mean we don’t need to do the full clone and build of UE4, and instead just need to put this .cpp file in a correct spot? If so where do we put it? Thanks for the write up as well!

    Like

    • Besides the version listed in article (at minimum), you shouldn’t have to upgrade a full build to use it. Then again, Epic Games’ updates are like Pandora’s Box at this rate so fingers crossed.

      Like

  6. First of all, thank you. Based on what you wrote, I was able to write a Steam leaderboard. However, I have the following problem. The first time you call WriteLeaderBoardInteger, the values ​​are updated correctly on the Steam Leader Board. However, if you call Write LeaderBoardInteger to update its value in the second time, the value is not updated. Do you know why? I am using UE4 4.21.

    Like

Leave a reply to LordIheanacho Cancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.