Forum rules - please read before posting.
Tech questions during the weekend? Drop in on the community Discord channel!

Steam Achievements with AC

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.

  • So, I think all that's needed (at least for simple unlock achievements) is to run this bit of code:

    using Steamworks;
    #if (SteamManager.Initialized) {
    SteamUserStats.SetAchievement("ACH_ID");
    SteamUserStats.StoreStats();}

    But I'm not sure how to use AC to do that. 
  • edited November 2016
    ummmm! You could create a custom action, just have a variable for the string AchievementID, then run the code inside the Run() method. you probably want to avoid running the code if the AchievementID is string.Empty and maybe have a try catch in case the AchievementID is incorrect. If I have the time I'll make it myself, but I'm kinda swamped in an AC - VRTK integration right now. I'll probably need to explore steamworks myself, but I don't have the time to read the api right now, if you can post more actions we could try to work them out into AC actions for easier use.
  • edited November 2016
    Ok, try this AC custom action. The code is untested though, cause I don't have the steamworks plugin yet. Let me know if there are any errors.
  • @Alverik thanks for your help! I really appreciate you taking time from your busy schedule. 

    I was getting some errors at first and then figured out that I needed to change the code I wrote above to 

    using Steamworks;
    if (SteamManager.Initialized) {
    SteamUserStats.SetAchievement("ACH_ID");
    SteamUserStats.StoreStats();}

    and that fixed it (removing the "#" before "if" and removing "#endif"). Tested this through the Steam Client and it works :) You're a life saver, my friend! Hope others will be able to put that to use as well. 
  • edited December 2016
    Cool, if I can I'll add the script to the wikia this week, else I'll do it when I have the time. Anyway, glad to hear you got it working! Cheers!
  • edited December 2016
    Right, I added the action to the wikia, anyone interested can find it here. (copy pasting in the wikia was a pain in the ass as usual, lol).
  • Hey Alverik,

    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

  • edited February 2017
    Weird, check if it was pasted correctly. A bracket may have been missed or something. (here's the code again, I'll repost the code in the wikia just in case too)

    using UnityEngine;
    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
    }
  • Thanks! That takes care of most of the errors. Unfortunately, I get a new one:

    Assets/AdventureCreator/Scripts/CustomActions/ActionUnlockAchievement.cs(71,246): error CS1525: Unexpected symbol `end-of-file'
  • edited February 2017
    Weird, my copy-pasting missed a curly bracket. Sorry. I hate copy pasting, lol. Anyway add a } at the end. (The one in the wikia does have two closing curly brackets after the #endif like it should, so I guess I just got it wrong here in the forums.)
  • Many thanks, Alverik! No more errors :)

    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:
    image image
  • @jasong try using "ACH_DETOUR" as the ID instead
  • edited February 2017
    That worked! Many thanks witheredCrow!

    You guys are the best, hopefully this will help any others who might be just as clueless as me :)
  • edited May 2017
    Hey everyone,

    Thanks for all your help! Just wanted to resurrect this for anyone else who comes across it with a brief addendum that tripped me up: What witheredCrow mentions in the OP about 'running Steamworks.net' is important. Your AC project will need to have Steamworks.NET installed, or the scripts mentioned here will not work.

    You can do so via: https://steamworks.github.io/

    After that, it all worked perfectly! Note that the second curly bracket discussed does need to be added as well, though - for some reason it isn't in the wiki edition of the script either...? 

    Anyways, you all are indeed the best. Alverik, a shoutout shall be yours. :)
  • edited May 2017
    Stupid curly bracket, lol. Anyways, good to hear it helped. I've added the missing curly bracket in the article, it'll hopefully work right away for the next person that decides to use it.
  • Hey @Alverik
    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!
  • Someone else know the trick? 
  • I think this is more of a Steam issue and not something that can be achieved through AC. I could be wrong and someone please correct me if I am.

    I never could figure out how to reset achievements when I was debugging my game so I ended up creating another Steam account and testing through that. This means you will have to create another account every time you want to test them again. Not the most elegant solution I know and if anyone has a better solution I would love to know as well.

  • Thanks for your answer @jasong !
    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!
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.
Do NOT follow this link or you will be banned from the site!