Topic: Trouble with Steamworks and challenge mode

I created a code for Steam Achievements

#if UNITY_STANDALONE
using Steamworks;
using UnityEngine;

public class AchievementManager : MonoBehaviour
{
    // Our GameID
    private CGameID m_GameID;

    private bool tzompantliTested = false;
    private bool hasTzompantli= false;


    // Callback for Achievement stored
    protected Callback<UserAchievementStored_t> m_UserAchievementStored;

    public static AchievementManager instance = null;

    private Achievement[] Achievements = new Achievement[] {
        new Achievement(AchievementEnum.ACH_VAM_WIN, "La Mujer Vámpiro", ""),
        new Achievement(AchievementEnum.ACH_YOT_WIN, "Yotecatl", ""),
        new Achievement(AchievementEnum.ACH_DRA_WIN, "Drakenhaussen", ""),
        new Achievement(AchievementEnum.ACH_KIT_WIN, "Kitty", ""),
        new Achievement(AchievementEnum.ACH_FAU_WIN, "El Fausto", ""),
        new Achievement(AchievementEnum.ACH_PIS_WIN, "Piscuario", ""),
        new Achievement(AchievementEnum.ACH_CHA_WIN, "Charro Negro", ""),
        new Achievement(AchievementEnum.ACH_LLO_WIN, "Llorona", ""),
        new Achievement(AchievementEnum.ACH_PEN_WIN, "Penumbra", ""),
        new Achievement(AchievementEnum.ACH_LUZ_WIN, "Luzbelle", ""),
        new Achievement(AchievementEnum.ACH_VAM_CHA, "Challenge mujer vampiro", ""),
        new Achievement(AchievementEnum.ACH_YOT_CHA, "Challenge Yotecatl", ""),
        new Achievement(AchievementEnum.ACH_DRA_CHA, "Challenge Drakkenhaussen", ""),
        new Achievement(AchievementEnum.ACH_KIT_CHA, "Challenge Kitty", ""),
        new Achievement(AchievementEnum.ACH_FAU_CHA, "Challenge Fausto", ""),
        new Achievement(AchievementEnum.ACH_PIS_CHA, "Challenge Piscuario", ""),
        new Achievement(AchievementEnum.ACH_CHA_CHA, "Challenge Charro", ""),
        new Achievement(AchievementEnum.ACH_LLO_CHA, "Challenge Llorona", ""),
        new Achievement(AchievementEnum.ACH_PEN_CHA, "Challenge Penumbra", ""),
        new Achievement(AchievementEnum.ACH_LUZ_CHA, "Challenge Luzbelle", ""),
        new Achievement(AchievementEnum.ACH_VS_COUNT, "Contador vs", ""),
        new Achievement(AchievementEnum.ACH_ONLINE_COUNT, "Contador Online", ""),
        new Achievement(AchievementEnum.ACH_MOS_COUNT, "Contador Mostro", ""),
        new Achievement(AchievementEnum.ACH_ESC_COUNT, "Contador Escapes", ""),
        new Achievement(AchievementEnum.ACH_COUNT_COUNT, "ContadorCounter", ""),    
        new Achievement(AchievementEnum.ACH_3D, "3D BABY", ""),    
        
    };


    //La clase Achievement es un POJO que encapsula algunas propiedades del logro
    public class Achievement
    {
        public AchievementEnum AchievementID;
        public string Name;
        public string Description;
        public bool Achieved;

        ///
        /// Creates an Achievement. You must also mirror the data provided here in [url]https://partner.steamgames.com/apps/achievements/yourappid[/url]
        ///
        /// The "API Name Progress Stat" used to uniquely identify the achievement.
        /// The "Display Name" that will be shown to players in game and on the Steam Community.
        /// The "Description" that will be shown to players in game and on the Steam Community.
        public Achievement(AchievementEnum achievementID, string name, string desc)
        {
            AchievementID = achievementID;
            Name = name;
            Description = desc;
            Achieved = false;
        }
    }

    // Un simple Enum con los logros correspondientes
    public enum AchievementEnum : int
    {
        ACH_VAM_WIN,
        ACH_YOT_WIN,
        ACH_DRA_WIN,
        ACH_KIT_WIN,
        ACH_FAU_WIN,
        ACH_PIS_WIN,
        ACH_CHA_WIN,
        ACH_LLO_WIN,
        ACH_PEN_WIN,
        ACH_LUZ_WIN,
        ACH_VAM_CHA,
        ACH_YOT_CHA,
        ACH_DRA_CHA,
        ACH_KIT_CHA,
        ACH_FAU_CHA,
        ACH_PIS_CHA,
        ACH_CHA_CHA,
        ACH_LLO_CHA,
        ACH_PEN_CHA,
        ACH_LUZ_CHA,
        ACH_VS_COUNT,
        ACH_ONLINE_COUNT,
        ACH_MOS_COUNT,
        ACH_ESC_COUNT,
        ACH_COUNT_COUNT,
        ACH_3D
    }


    // Use this for initialization
    void Start()
    {
        if (instance == null)
        {
            instance = this;
        }
        else
        {
            Destroy(gameObject);
        }

        DontDestroyOnLoad(gameObject);

        //DebugAchievements();
    }

    private void DebugAchievements()
    {
        if (SteamManager.Initialized)
        {
            Debug.Log("SteamManager initialized.");

            // Cache the GameID for use in the Callbacks
            m_GameID = new CGameID(SteamUtils.GetAppID());
            m_UserAchievementStored = Callback<UserAchievementStored_t>.Create(OnAchievementStored);
            PrintAchievements();
        }
        else
        {
            Debug.LogWarning("SteamManager NOT initialized!");
        }
    }

    private void PrintAchievements()
    {
        foreach (Achievement ach in Achievements)
        {
            bool ret = SteamUserStats.GetAchievement(ach.AchievementID.ToString(), out ach.Achieved);
            if (ret)
            {
                ach.Name = SteamUserStats.GetAchievementDisplayAttribute(ach.AchievementID.ToString(), "name");
                ach.Description = SteamUserStats.GetAchievementDisplayAttribute(ach.AchievementID.ToString(), "desc");

                Debug.LogFormat("Achievement Name: {0} --- Unlocked: {1}", ach.Name, ach.Achieved);
            }
            else
            {
                Debug.LogWarning("SteamUserStats.GetAchievement failed for Achievement " + ach.AchievementID + "\nIs it registered in the Steam Partner site?");
            }
        }
    }

    ///
    /// Calls SetAchiemement. Steam docs:
    /// This method sets a given achievement to achieved and sends the results to Steam. You can set a given achievement multiple times so you don't
    /// need to worry about only setting achievements that aren't already set.
    /// This is an asynchronous call which will trigger two callbacks: OnUserStatsStored() and OnAchievementStored()
    ///
    ///
    public void UnlockAchievement(AchievementEnum achievement)
    {
        SteamUserStats.SetAchievement(achievement.ToString());
        SteamUserStats.StoreStats();
    }
    
        public void EraseAchivement()
    {
        SteamUserStats.ResetAllStats(true);
    }

    public bool unlockTzompantliCharacter()
    {
        //542240  574980
        AppId_t TzompantliID = new AppId_t(542240);

        if (!tzompantliTested)
        {
            hasTzompantli = SteamApps.BIsSubscribedApp(TzompantliID);

            if(hasTzompantli)
                Debug.Log("Si compró Tzompantli, ya tiene nuevo mona!");
            else
                Debug.Log("No compró Tzompantli");
            tzompantliTested = true;
        }



        return hasTzompantli;
    }


        //-----------------------------------------------------------------------------
        // Purpose: An achievement was stored
        //-----------------------------------------------------------------------------
        public void OnAchievementStored(UserAchievementStored_t pCallback)
    {
        // We may get callbacks for other games' stats arriving, ignore them
        if ((ulong)m_GameID == pCallback.m_nGameID)
        {
            if (0 == pCallback.m_nMaxProgress)
            {
                Debug.Log("Achievement '" + pCallback.m_rgchAchievementName + "' unlocked!");
            }
            else
            {
                Debug.Log("Achievement '" + pCallback.m_rgchAchievementName + "' progress callback, (" + pCallback.m_nCurProgress + "," + pCallback.m_nMaxProgress + ")");
            }
        }
    }
}

#endif

It has worked so far, but just when I try to add a code to call it from ChallengeMode.cs

AchievementManager.instance.UnlockAchievement(AchievementManager.AchievementEnum.ACH_VAM_CHA);
                    break;

it sends me a message

Assets\UFE\Engine\Scripts\Core\Manager\ChallengeMode.cs(167,21): error CS0103: The name 'AchievementManager' does not exist in the current context

I can make that simple line of code to run from defaultBattleGUI.cs with no issues, but not from ChallengeMode.cs, someone knows what I'm doing wrong? thank you

Share

Thumbs up Thumbs down

Re: Trouble with Steamworks and challenge mode

I think it's due to something with the UFE3D assembly definition.
It seems like it prevents other code from being recognized.
I haven't messed with assembly definitions before so not sure how to fix it.
https://i.imgur.com/G8HNgiD.png
https://i.imgur.com/aQHes5q.png
https://i.imgur.com/opMhBJO.png

Share

Thumbs up Thumbs down

Re: Trouble with Steamworks and challenge mode

Like FreedTerror mentioned, the reason for it is in fact the assembly definition.
There are 2 ways you can fix this:
Use the inherited class instead
There is a class called "DefaultChallengeModeGUI". This class inherits ChallengeMode and its outside the assembly scope. You can access anything from the parent class as well as make references to your singleton.

Delete the assembly definitions (Source version)
Delete the following files:
\UFE\Engine\Scripts\Core\UFE3D.asmdef
\UFE\Engine\Editor\UFE3D.Editor.asmdef
These definitions are not needed in the Source version. Deleting these files will "free" the core scripts from enclosure and you will be able to make your static reference from there.

Like UFE? Please rate and review us on the Asset Store!
Questions about the Forum? Check out our Karma FAQ.
Don't forget to check our discord channel.