Hi, I'm working on getting my game ready for Steam and was wondering if anyone has successfully gotten Steam Achievements to work with their AC game?
I currently have in-game achievements which I use global variables to unlock. I set the variable to "true" when the player gets the achievement. Then when they open the Achievements menu, I check if the var is true or false to turn on/off menu elements.
I'm using Steamworks.NET, have the game running on Steam and have the Achievement Configuration all set up in Steamworks.
I'm not a programmer, so I'm struggling a bit with the achievements part. If anyone would be willing to share their custom script for using Steam Achievements with AC, that would be amazing. I'd be happy to give you a shout out in the credits of my game.
Comments
I'm curious about this too.
using Steamworks;
Thanks for add the code to the wiki! I'm getting some errors though (see below) even though I have the Steamworks.net plugin installed. Not sure if this is related to what witheredCrow mentioned, which I also tried to comb through and fix without much luck. Any help would be much appreciated!
Assets/AdventureCreator/Scripts/Actions/ActionUnlockAchievement.cs(85,43): error CS1010: Newline in constant
Assets/AdventureCreator/Scripts/Actions/ActionUnlockAchievement.cs(89,0): error CS1525: Unexpected symbol `achievements'
Assets/AdventureCreator/Scripts/Actions/ActionUnlockAchievement.cs(89,13): error CS1525: Unexpected symbol `.'
Assets/AdventureCreator/Scripts/Actions/ActionUnlockAchievement.cs(89,19): error CS1010: Newline in constant
Assets/AdventureCreator/Scripts/Actions/ActionUnlockAchievement.cs(91,1): error CS1002: ; expected
using System;
using Steamworks;
#if UNITY_EDITOR
using UnityEditor;
#endif
/* By Alvaro Urrutia Luna (Alverik)
* Custom action to
* Unlock Steam achievements.
*/
namespace AC
{
[System.Serializable]
public class ActionUnlockAchievement : Action
{
// Declare variables here
public string AchievementID = "";
public ActionUnlockAchievement()
{
this.isDisplayed = true;
category = ActionCategory.Custom;
title = "Unlock Steam Achievement.";
description = "Unlocks an steam Achievement.";
}
override public float Run ()
{
//your action:
if (SteamManager.Initialized)
{
if(AchievementID!=String.Empty || AchievementID!="")
{
try
{
SteamUserStats.SetAchievement(AchievementID);
SteamUserStats.StoreStats();
}
catch(Exception e)
{
Debug.LogError("Error while setting steam achievements... " + e);
}
}
}
//end the action
return 0f;
}
#if UNITY_EDITOR
override public void ShowGUI ()
{
// Action-specific Inspector GUI code here
AchievementID = EditorGUILayout.TextField("Achievement ID: ", AchievementID , GUILayout.ExpandWidth(true));
AfterRunningOption ();
}
public override string SetLabel ()
{
// Return a string used to describe the specific action's job.
string labelAdd = "Unlocks an steam Achievement.";
return labelAdd;
}
#endif
}
Assets/AdventureCreator/Scripts/CustomActions/ActionUnlockAchievement.cs(71,246): error CS1525: Unexpected symbol `end-of-file'
So, now I'm running into an issue getting my achievement to unlock. I have one achievement setup in Steamworks with the ID: 1/0. I've done a few tests where I plugged in "0" "1" and "1/0" into the Custom Action, but when running those actions in the build nothing happens, my achievement stays locked. The setup seems pretty straightforward, but I must be overlooking something. Screenshots below:
You guys are the best, hopefully this will help any others who might be just as clueless as me
Your script works great, just tested in these days!
Sorry to bother you but you seems very expert on this, so I was wondering if there is the possibility, with another script, to do the opposite operation, that's LOCK the Steam achievements.
That's for debug testing, so I can create a temporary button with the ActionLOCKAchievement so I can re-lock the achievement I unlocked...
Thanks in any case!
Bye-bye!
I asked because I saw a videotutorial here:
https://www.youtube.com/watch?v=PzMjsSJ0o6E&t=740s
At minute 12:25 the guy set a command called SteamUserStats.ClearAchievement(ID) and the achievement with that ID is reset/relocked... so I think that modifing the current script made from @Alverik could be possible.
Thanks anyway!
Bye!