Forum rules - please read before posting.

A little help with Custom Action.

Hello everyone. I'm writing a custom action to unlock achievements. I have a list of achievement names in a separate script, and I want a drop down menu of those names to select the achievement, which would set the id of the selected achievement to unlock.

I'm trying this (only the relevant parts):

protected int selectedAchievement;
public override void ShowGUI()
    {
        // Action-specific Inspector GUI code here
        List<string> namesList = new List<string>();

        foreach (string name in Achievements.names)
        {
            namesList.Add(name);
        }

        selectedAchievement = EditorGUILayout.Popup("Achievement name: ", selectedAchievement, namesList.ToArray()); 
    }

The dropdown menu correctly displays the achievement names and I can select one. But if I restart the Unity Editor, the selected achievement reverts back to the first one in the list. There's no reason for the int to be protected. I just copied that from another AC action script because it wasn't working. Am I missing something? Why wouldn't this be working? I'm using AC v1.74.2 and Unity 2022.3.39f1.

Comments

  • selectedAchievement needs to be serialized for its value to be saved.

    Either make it public, or assign it the [SerializeField] attribute.

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.