Page cover

Achievement Object

Like what your seeing?

Introduction

public class AchievementObject : ScriptableObject

The AchievementObject is generated by importing achievements from the Steam Developer Portal. You do this by selecting your Steam Settings object and expanding the Achievements section and clicking the Import button.

The simulation must be running (click Play in Unity) in order for this to work

This is because the Steam API must be initialized and updating to return results

The AchievementObject scriptable object simply exposes the AchievementData structure to Unity's ScriptableObject. This allows you to create references in your scripts such that you can drag and drop the achievement and allows us to manage a UnityEvent that will raise when the achievement is locked or unlocked.

You do not have to use the ScriptableObject you can simply use the AchievementData structure if you are more comfortable with them.

Events

StatusChanged

public UnityBoolEvent StatusChanged;

This is raised when the achievement is cleared, set or reset through Heathen's tools and systems. It cannot detect when the achievement is modified outside of Heathen's systems.

The handler for this event would like the following

Fields and Attributes

Id

Returns the ID of the achievement, note in the editor you can both read and write this value however in a build you can only read this value. The write operation is only used when importing achievments from Steam whcih can only happen at development time in the editor.

Name

Returns the display name of the achievement, as with ID, in builds this can only be read, in the editor however it can be read and writen to in order to support the import of achievements at development time.

Description

Returns the description of the achievement, as with ID, in builds this can only be read, in the editor however it can be read and written to in order to support the import of achievements at development time.

Hidden

Returns the hidden flag for this achievement, as with ID, in builds this can only be read, in the editor however it can be read and written to in order to support the import of achievements at development time.

IsAchieved

This can be read to determine if the user has unlocked this achievement, this can be written to in order to unlock this achievement.

Note that if the achievement is set to write trusted only then the attempt to write to this achievement will simply do nothing.

UnlockTime

A nullable datetime expression indicating the date and time the achievement was achieved if any

Methods

Unlock

Unlocks the achievement for the local user or if on a game server pass in the user ID to unlock the achievement for a specific user.

The server version (takes the user paramiter) will only work from Steam Game Servers and only when the indicated user has been authenticated.

When in a client build this is the same as

ClearAchievement

Clears the achievement state for the local user in client builds (do not pass the user parameter). For server builds you would pass in the user parameter to clear the achievement for the indicated user. The server version (takes the user parameter) will only work from Steam Game Servers and only when the indicated user has been authenticated.

GetAchievementStatus

Gets the achievement state for this achievement for the indicated user. This is only available from Steam Game Servers and only when the indicated user has been authenticated and its states requested. See the API.StatsAndAchievements interface for details

GetAchievementAndUnlockTime

Returns the unlock status and unlock time if relevant for the achievement.

GetIcon

Gets the current icon for the achievement. This is sinsative to the user's unlock/lock status. So if the user has achieved this achievement this will be the "unlock" icon, if not it will be the "locked" icon.

Store

This simply calls StatsAndAchievements.Client.StoreStats() and is only used on client builds to store any updated stats and achievements to the backend.

Last updated