How do you get an enum to show in the inspector on unity?

Should I share code for my specific project or is there a simple answer to this?

public enum GoalType
{
1,
2
}

ENUM won’t show as a drop down menu, other public types are appearing.

1 Like

Have you declared a variable of that enum type?

public GoalType goalType;
4 Likes

Are “1” and “2” legal enumerated values? I was under the impression that enum value names followed the general rule for identifiers, and identifiers in C# have to start with a letter or an underscore.

Check your console for error messages.

Not at all. @addscion the code you wrote above is nonsense. I suggest starting with the C# docs on enums to understand how to make them. Once you make one, then as Godlike Bob suggested, just make a public variable to set it in the inspector.

WARNING: remember Unity does NOT serialize the enum but rather the integer equivalent, so if you renumber or delete any enums that you have already “burned into” scenes or prefabs, they will all become silently incorrect. Use caution and ONLY add new identifiers to the end of enums, or else hard-wire the integers by assignment.

I use it this way :

    public enum MyEnum // *
    {
        Option1,
        Option2,
        Option3,
    }
    public MyEnum myEnum;

EDIT : Removed the unuseful index…

To test what option is selected

if (myEnum == MyEnum.Option1) // for example
3 Likes