Skip to content

Steam achievements in Godot with GodotSteam

5 min readBy Eduardo Orellana ·

To add Steam achievements to a Godot 4 game: create them (and any stats) in Steamworks and publish the change (the game does not need to be released), then in GDScript call Steam.setAchievement("API_NAME") followed by Steam.storeStats(). storeStats() is what uploads it and triggers Steam's pop-up. Read one with Steam.getAchievement(), clear it with Steam.clearAchievement(), and show progress with Steam.indicateAchievementProgress(). GodotSteam 4.14 and later sync stats and achievements at boot, so no request call is needed. Valve limits a game to 100 achievements at first, raised once the game reaches its Profile Features threshold.

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

The pop-up only appears after storeStats()

The most common achievement bug in Godot is not a bug: the achievement is set but never stored. setAchievement() marks it in Steam's local cache; storeStats() sends it to Steam's servers, and only then does the overlay pop-up appear. Valve's own documentation describes the same pair for its C++ API: SetAchievement for each unlocked achievement, then StoreStats to upload, which fires the stored callbacks and the overlay notification.

The second most common bug is in Steamworks, not Godot: achievements defined but not published. Until you publish the changes on the Steamworks side, setting or reading them fails, and no amount of GDScript will fix it.

Sources: GodotSteam: Stats and Achievements, Steamworks: Stats and Achievements, GodotSteam: User Stats class.

In Steamworks

  1. Create each achievement on the app's Stats & Achievements page with an API name, a display name, a description, and locked and unlocked icons. Names and descriptions can be localized; Valve asks that names and icons be all-ages appropriate.
  2. Create any stats behind progress achievements (integer or float, and whether they may only increase).
  3. Publish the changes. The game does not need to be approved or released for achievements to work in testing.

Valve limits games to 100 achievements at first; more become available once the game reaches the threshold for Profile Features. Before release, earned achievements do not show in the Community or library, so check them in-game while testing.

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

In GDScript

With GodotSteam initialized in an autoload and callbacks running every frame, unlock an achievement by its API name, and keep a stat for progress achievements:

Sources: GodotSteam: Stats and Achievements, GodotSteam: User Stats class.

GDScript
func unlock(api_name: String) -> void:
	if not Steam.setAchievement(api_name):
		push_warning('No achievement called %s' % api_name)
		return
	Steam.storeStats()

func add_kill() -> void:
	var kills: int = Steam.getStatInt('kills') + 1
	Steam.setStatInt('kills', kills)
	if kills == 50:
		Steam.indicateAchievementProgress('KILL_100', kills, 100)
	if kills >= 100:
		Steam.setAchievement('KILL_100')
	Steam.storeStats()

Reading, resetting, testing

  • Read: Steam.getAchievement(name) returns a dictionary; ret is false if the achievement does not exist, achieved tells you its state.
  • Clear one: Steam.clearAchievement(name), then storeStats().
  • Reset everything: Steam.resetAllStats(true) also resets achievements. Useful while testing; reset your own in-memory state afterwards.
  • 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.
  • Increment-only stats refuse a lower value, which protects against bugs and cheats.
  • Test with Steam running and signed in, under your game's own App ID once the achievements exist there; app 480's achievements are Valve's sample ones.

Sources: GodotSteam: Stats and Achievements, Steamworks: Stats and Achievements.

When to call storeStats()

Valve's guidance distinguishes cheap calls from expensive ones. Setting a stat only changes Steam's in-memory state and can happen whenever the value changes; storing uploads to Steam's servers and belongs at checkpoints: a level end, a boss kill, a return to the menu, and immediately after unlocking an achievement so the pop-up is not delayed. Calling storeStats() every frame floods the servers and can be rate-limited; never calling it means progress is lost when the game crashes.

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

Achievement icons and text

Every achievement has two icons, locked and unlocked, and they show in the overlay pop-up, the player's library and the store page's achievement preview. Make the locked icon a desaturated or silhouetted version of the unlocked one so the pair reads as the same achievement. Keep the display name short enough to fit a pop-up, and write the description as the condition ("Defeat the Warden without taking damage") rather than flavour text, because players read it to know what to do. Localize both if the game is localized; Valve serves the version that matches each player's language.

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

Leaderboards next door

Leaderboards use the same user-stats system. With GodotSteam, find a leaderboard by name, wait for its handle in the leaderboard_find_result signal, then upload a score with Steam.uploadLeaderboardScore(), choosing whether to keep the player's best score. Create the leaderboard in Steamworks first, or from code if you prefer, and decide its sort order and display type there. A daily or weekly board, keyed by date in its name, gives a small game a reason to come back.

Sources: Steamworks: Steam Leaderboards, GodotSteam: User Stats class.

Designing achievements players like

Achievements are part of the store page as well as the game: the count and a preview appear there, and players browse them in their library. A few habits from games that use them well:

  • Mark progress, not just completion: finishing chapter one, beating the first boss, reaching the ending.
  • Reward play styles: a no-damage run, a pacifist route, a speedrun, for the players who look for them.
  • Avoid grind for its own sake: "kill 10,000 enemies" reads as padding.
  • Use hidden achievements for spoilers, so story beats are not revealed in the list.
  • Keep them reachable after patches: removing or changing the condition for an achievement players were chasing generates angry reviews.

Resetting after a bad release

Steam has no global wipe of every player's achievements. If a buggy build unlocked achievements that should not have, Valve's documentation suggests a version stat: store a version number as a stat, and when a player's stored version does not match the one hardcoded in the new build, call the reset for that player and update the stat. Use it sparingly; resetting legitimately earned achievements upsets players more than a few undeserved ones. Test the reset path on a second account before shipping it: a version stat that is never stored resets every player on every launch, which is worse than the bug it was meant to fix. Call storeStats() after updating the version, then restart the game and confirm earned achievements are still there.

Valve's Steamworks documentation: Stats and Achievements.

Where Flockbay fits

Flockbay builds games on the official Godot engine; ask its AI for Steam achievements and it writes the GodotSteam calls into your project, which you own, while the achievements themselves are defined and published by you in Steamworks. Building is free to start.

Questions

Why does my Steam achievement not pop up in Godot?
Usually because Steam.storeStats() was not called after Steam.setAchievement(), the achievements were not published in Steamworks, or callbacks are not running.
How many achievements can a Steam game have?
100 at first, by Valve's default limit. More become available once the game reaches the threshold for Steam's Profile Features.
Do Steam achievements work before my game is released?
Yes, for testing: once they are published in Steamworks, your game can set and read them under its own App ID. Earned achievements do not show in the Community or library until the game is visible to the community, so check them in-game.
What is indicateAchievementProgress for?
It shows Steam's progress pop-up for an achievement that is not unlocked yet, such as 50 of 100. Call it at meaningful milestones, not on every increment.

Flockbay builds Godot games, free to start, and writes Steam features into them on request.

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.