Links

Achievement Object

​

Like what your seeing?

Support us as a GitHub Sponsor and get instant access to all our assets, exclusive tools and assets, escalated support and issue tracking and our gratitude. These articles are made possible by our GitHub Sponsors ... become a sponsor today!

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
void HandleEvent(bool value)
{
//Do Work
}

Fields and Attributes

Id

public string Id => get;
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

public string Name => get;
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

public string Description => get;
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

public bool Hidden => get;
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

public bool IsAchieved { get; set; }
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

public DateTime? UnlockTIme get;
A nullable datetime expression indicating the date and time the achievement was achieved if any

Methods

Unlock

public void Unlock();
public void Unlock(CSteamID user);
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
achievement.IsAchieved = true;

ClearAchievement

public void CLearAchievement();
public void ClearAchievement(UserData user);
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

public bool GetAchievementStatus(CSteamID user);
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

public (bool unlocked, DateTime unlockTime) GetAchievementAndUnlockTime(UserData user)
Returns the unlock status and unlock time if relevant for the achievement.

GetIcon

public void GetIcon(Action<Texture2D> callback)
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

public void Store()
This simply calls StatsAndAchievements.Client.StoreStats() and is only used on client builds to store any updated stats and achievements to the backend.
You should not call this every time you update the value of a stat or achievement. The intended purpose from Valve is that you can update your stats and achievements in real time during gameplay and then at key points such as at the end of a mission or similar store those stats to the backend.
​
The notification of a stat or achievement being updated only happens when you call store stats or when the game closes.
​
The Store Stats function is rate limited so if you call it to frequiently the Steam API will ignore you.