Stats Examples
This section provides practical examples of using the Steam Stats subsystem to track player progress, record gameplay metrics, and synchronize numeric values with Steam.
All examples below are shown using Blueprint nodes, with equivalent functionality available through the C++ API.
Prerequisites
Before using any Stats-related nodes, the following conditions must be met:
- Stats must be created and published in Steamworks
- Stat names must exactly match the identifiers defined in Steamworks
Stat creation and configuration is managed through Steamworks and must be completed before stats can be accessed or modified at runtime.
Modifying Stat Values
This example demonstrates how to modify Steam stat values during gameplay using Set and Increment nodes.
Stat modification nodes update the local cached value of a stat. Changes are not immediately sent to Steam, which allows stats to be updated freely during gameplay without triggering network requests on every change.
Increment nodes are typically used for cumulative progress tracking. In this example, Increment Stat Int is used to increase the LevelsCompleted stat each time a level is finished, while Increment Stat Float adds the duration of the current session to the TotalPlayTimeHours stat.
Set nodes are used for authoritative values that should overwrite the previous stat value. In this example, Set Stat Int updates the HighestScore stat using the final score achieved by the player, and Set Stat Float updates the BestLapTime stat using the current lap time.
This pattern is commonly used at the end of a match, after completing an objective, or when a gameplay milestone is reached.
Reading Stat Values
This example demonstrates how to retrieve the current value of a Steam stat for the local user.
Stat values are read using the Get Stat Int and Get Stat Float nodes, depending on whether the stat is defined as an integer or a floating-point value in Steamworks.
The returned value represents the last known local state synchronized from Steam and can be used to display player progression, update UI elements, or drive gameplay logic.
Reading stat values does not trigger any network communication and is safe to perform frequently, such as during UI updates or menu rendering.
Storing Stats to Steam
After modifying one or more stats, changes can be synchronized with Steam using the Store Stats node.
Calling Store Stats uploads all modified stats to the Steam backend in a single operation.
Stat synchronization is not strictly required after every change. Steam may automatically store stats at certain points, such as when the game exits, but this behavior is not guaranteed.
For reliable and immediate persistence, it is recommended to explicitly call Store Stats after important gameplay events.
Resetting Stats
This example demonstrates how to reset all Steam stats for the local user.
The Reset All Stats node clears all stored stat values and can optionally reset achievements as well, depending on the provided flag.
Resetting stats is commonly used for testing, debugging, or development-only reset options. This operation affects the local user immediately and synchronizes the reset state with Steam.
Important Notes
- Stat names are case-sensitive and must exactly match Steamworks definitions
- Stat values are modified locally and only sent to Steam when stored
- Avoid calling Store Stats excessively; batch stat updates when possible
- Always store stats after important progression milestones