Unlocking Achievements from Stats

There are achievements that require the player to do some action a certain number of times to be unlocked, for example: kill 100 enemies, jump 50 times, collect 1000 coins, etc. Fortunately, Steam has a stats system that helps track the player's progress and even unlocks achievements automatically when a certain number (defined by you) is reached. For this to work, you must interact with a stat rather than directly interacting with the achievement.

Use the code below to increment a stat:

[SerializeField]
SteamAchievements steamAchievements;

steamAchievements.IncrementStat("STAT_JUMP");

You can also increment a stat in the Unity Editor by associating the SteamAchievements script with any event, as shown in the following example:

A stat being incremented on a button click event

Note that STAT_JUMP corresponds to the Steamworks Stat ID:

Stat configuration in Steamworks

When increasing a stat, if the amount required to unlock the achievement is reached, the achievement will be unlocked automatically.

Important: to learn more about Stats, as well as how to enable and configure it, please refer to the official documentation.

Last updated