Skip to content

Steam achievements in Unity

5 min readBy Eduardo Orellana ·

For Steam achievements in Unity: create and publish them in Steamworks, then from C# set one and store stats. With Steamworks.NET that is SteamUserStats.SetAchievement("API_NAME") followed by SteamUserStats.StoreStats(); with Facepunch.Steamworks it is new Achievement("API_NAME").Trigger(), which sets and stores. The overlay pop-up appears only once the stats are stored, and only while the game runs under Steam with your App ID. Valve limits a game to 100 achievements at first; reset them while testing with SteamUserStats.ResetAllStats(true) or the Steam console's reset_all_stats.

AppImage, x86_64. Ubuntu 22.04, Debian 12, Fedora 39 or newer.

Intel or AMD Chromebook, with Linux turned on.

Download for macOSDownload for WindowsDownload for Linux

Set, then store

Steam keeps achievements and stats in a local cache until you store them. Set an achievement without storing, and nothing reaches Steam's servers and no pop-up shows. Every engine's integration has the same two steps because they are Valve's: SetAchievement marks it, StoreStats uploads it and makes the overlay show the notification.

Unity has no Steam support built in, so the calls come from a C# wrapper around Valve's SDK. Two are widely used: Steamworks.NET, a thin, complete mapping of Valve's API, and Facepunch.Steamworks, a higher-level library with friendlier C#. Both reach the same Steam features; our Steamworks.NET or Facepunch guide compares them. The examples below show both.

Valve's Steamworks documentation: Stats and Achievements, ISteamUserStats Interface.

In Steamworks first

  1. Create each achievement on the app's Stats & Achievements page: an API name, a display name, a description, and locked and unlocked icons. Names and descriptions can be localized.
  2. Create any stats that drive progress achievements, as integers or floats, marking those that may only increase.
  3. Publish the changes. The game does not have to be released for achievements to work in testing.

Valve limits games to 100 achievements at first, with more available once the game reaches the threshold for Profile Features. Before release, earned achievements do not appear in the Community or library, so verify them in-game.

Valve's Steamworks documentation: Stats and Achievements, Step by Step: Achievements.

Steamworks.NET

After SteamAPI.Init() succeeds (the usual SteamManager component handles it), set and store:

Sources: Steamworks.NET: Getting Started, Steamworks: Step by Step: Achievements.

C#
using Steamworks;

public static class Achievements {
    public static void Unlock(string apiName) {
        if (!SteamManager.Initialized) return;
        SteamUserStats.SetAchievement(apiName);
        SteamUserStats.StoreStats();
    }

    public static void AddKill() {
        if (!SteamManager.Initialized) return;
        SteamUserStats.GetStat("kills", out int kills);
        kills++;
        SteamUserStats.SetStat("kills", kills);
        if (kills == 50) SteamUserStats.IndicateAchievementProgress("KILL_100", 50, 100);
        if (kills >= 100) SteamUserStats.SetAchievement("KILL_100");
        SteamUserStats.StoreStats();
    }
}

Facepunch.Steamworks

After SteamClient.Init(appId), the same ideas with objects:

Sources: Facepunch.Steamworks: Achievement.cs, Facepunch.Steamworks Wiki: Achievement.Trigger.

C#
using Steamworks;
using Steamworks.Data;

var achievement = new Achievement("FIRST_WIN");
achievement.Trigger(); // sets and stores

SteamUserStats.AddStat("kills", 1);
SteamUserStats.StoreStats();

Run callbacks, or nothing comes back

Steam answers through callbacks. Steamworks.NET's SteamManager calls SteamAPI.RunCallbacks() every frame in Update(); Facepunch.Steamworks processes callbacks for you after SteamClient.Init() unless you turn that off. If your manager object is destroyed on a scene load, or disabled, callbacks stop, and achievements set afterwards may never store. Keep the Steam manager in a persistent object (DontDestroyOnLoad) that lives for the whole session.

Sources: Steamworks: Step by Step: Achievements, Steamworks.NET: Getting Started, Facepunch.Steamworks Wiki: SteamClient.Init.

When the pop-up does not show

  • Stats were not stored after setting.
  • The achievements were not published in Steamworks.
  • The API name does not match exactly; names are case-sensitive.
  • The game is not running under Steam, or the App ID is wrong; in the editor, a steam_appid.txt with your App ID in the project root lets SteamAPI.Init() succeed while the Steam client runs. Never ship that file.
  • Callbacks stopped because the Steam manager was destroyed or disabled.
  • The overlay is off for the game or failed to hook, which hides the pop-up even though the achievement unlocked; check the player's profile to confirm.

Sources: Steamworks API Overview, Steamworks.NET: Installation.

When to store, and how often

Valve's documentation separates cheap calls from expensive ones. Setting a stat or an achievement only changes Steam's in-memory state, so do it the moment it happens. Storing uploads to Steam's servers, so do it at checkpoints: the end of a level, a boss kill, a return to the main menu, the game closing, and straight after an achievement unlocks so the pop-up appears on time. Storing every frame or every kill floods the servers and can be throttled; never storing loses progress whenever the game crashes or the player quits from the task manager.

Valve's Steamworks documentation: ISteamUserStats Interface, Stats and Achievements.

Stats and leaderboards ride along

The same user-stats system carries stats and leaderboards. Stats you define in Steamworks (kills, distance, wins) can drive achievements automatically if you link them there, and they persist across devices with the player's Steam account. Leaderboards are found by name and take uploaded scores: in Steamworks.NET through FindLeaderboard and UploadLeaderboardScore with CallResult handlers, in Facepunch.Steamworks through SteamUserStats.FindOrCreateLeaderboardAsync and the leaderboard's SubmitScoreAsync. Create them in Steamworks first, or from code, and choose the sort order and display type deliberately; a time leaderboard sorted the wrong way is a classic launch-day bug.

Sources: Stats and Achievements, Steam Leaderboards, Facepunch.Steamworks Wiki: FindOrCreateLeaderboardAsync, Facepunch.Steamworks Wiki: Leaderboard.SubmitScoreAsync.

Designing achievements players like

Achievements show on the store page as well as in the game, so they are part of how the game presents itself. Habits from games that use them well:

  • Mark the journey: the first chapter, the first boss, the ending, so most players earn several.
  • Reward ways of playing: a no-damage run, a speedrun, a pacifist route, for the players who hunt for them.
  • Avoid grind for its own sake; "collect 10,000 coins" reads as padding.
  • Hide the spoilers with hidden achievements, so story beats are not given away in the list.
  • Pair locked and unlocked icons so they read as the same achievement, and write descriptions as conditions players can act on.
  • Never remove one players are chasing; changing a condition after release generates reviews.

Valve's Steamworks documentation: Step by Step: Achievements.

Testing and resetting

  • Reset in code: SteamUserStats.ResetAllStats(true) in Steamworks.NET clears stats and achievements; Facepunch has SteamUserStats.ResetAll(true).
  • Reset without code: start Steam with its console (steam.exe -console) and use achievement_clear with the App ID and achievement name, or reset_all_stats with the App ID.
  • After a buggy release: Steam has no global wipe; Valve suggests storing a version stat and resetting a player's stats when it does not match the new build's number.
  • Test the built player, launched from Steam, not just the editor.
  • Keep a test account whose stats you reset freely, so your own main account's achievements stay meaningful.
  • Read the global percentages after launch: Steam shows each achievement's global unlock rate on its community page. One that almost nobody earns after a month may be bugged; one that everybody earns in the first minute may be teaching nothing.

Sources: Stats and Achievements, Facepunch.Steamworks Wiki: SteamUserStats.ResetAll.

Where Flockbay fits

Flockbay builds games on the official Godot engine, where its AI writes GodotSteam achievements on request; the steps in Steamworks are identical, and our Godot achievements guide has the GDScript version. For a Unity project, the C# above is the route. Building in Flockbay is free.

Questions

Why does my Steam achievement not pop up in Unity?
Usually because StoreStats() was not called after SetAchievement(), the achievements were not published in Steamworks, callbacks stopped running, or the game is not running under Steam with your App ID.
Steamworks.NET or Facepunch.Steamworks for achievements?
Either works. Steamworks.NET mirrors Valve's API call for call; Facepunch.Steamworks wraps it in friendlier C#, where Achievement.Trigger() sets and stores in one call.
How do I test Steam achievements in the Unity editor?
Put a steam_appid.txt with your App ID in the project root, keep the Steam client running and signed in, and press Play; SteamAPI.Init() then succeeds. Test the built player from Steam before release, and never ship the text file.
How many achievements can a Steam game have?
100 at first, by Valve's default limit, with more available once the game reaches the threshold for Profile Features.

Flockbay builds games for free on Godot, with GodotSteam for Steam features.

Download Flockbay free

AppImage, x86_64. Ubuntu 22.04, Debian 12, Fedora 39 or newer.

Intel or AMD Chromebook, with Linux turned on.

Download for macOSDownload for WindowsDownload for Linux

Flockbay

The free AI game maker for Windows, macOS and Linux.