Unity to Steam

Steam integration with Unity – Achievements, Leaderboards, Building

Unity to Steam


Setting up Steam integration for Unity. The video goes into the basics of creating achievements and leaderboards using the Unity Steamworks package. Also covers building/uploading to Steam via the Steamworks SDK. No paid addons used.


Beyond the video, I’ve also included some possible implementation for displaying the leaderboard data.
Full script below (Creative Commons 4.0)

Once you have the Steam Manager in the scene, you can set up the AchiMan below

The achiID struct contains a section for steamID and androidID by default but simply add/remove any integrations you need. You set the key’s in the editor via the achiIDs variable, and then just pass in an index to UnlockAchi when you want to unlock an achievement.

The LeadMan is a little more complicated. It finds the Leaderboard “Highscores” in the Awake function so be sure to change the Script Execution Order under Project Settings and place this script to execute time after Steam has been initialized.

Rather than using the usual CallBack that’s called each Update in the SteamManager, it works using CallResults so it works asynchronously. This means you can’t just set GetLeaderBoardData to return something, because it might be a few frames before OnLeaderboardDownloadResult actually goes through.
Instead, you want to put a call back at the end of OnLeaderboardDownloadResult itself. You’ll notice that the end of the script does this, passing the LeaderboardDataset that was just filled into my HighscoreUIMan (script below).

By changing the ELeaderboardDataRequest you can get different set of Leaderboard entries, I use three separate button to call GetLeaderBoardData, each passing in a different type and causing the LeaderboardDataset so the user can see global rank, friend’s ranks, and their own rank.
The number of entries can also be passed into the function.

This was not in the video but it’s quite straight forward. The FillLeaderboard function instantiates a number of prefabs (each containing 3 text fields: username, score, rank) to hold the data passed in from OnLeaderboardDownloadResult. It uses the vertical/horizontal layout groups to ensure everything fits correctly (see below)

Leave a Reply

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