[Flags] enum, 0 value is always "None" in dropdown even when explicitly defined otherwise

Issue #360 resolved
Former user created an issue

1)

            [Flags]
            public enum Species
            {
                Random  = 0, //this will always show as "None" when selected in the inspector dropdown list. It should show "Random"
                Human   = 1,
                Dragon  = 2,
                Bird    = 4,
            }

2)

        public Species Species;

4) 2018

5) Odin version: 1.1.0.0 beta 8

6) No

7) High Sierra

Comments (3)

  1. Port25

    Fix:

    EnumSelector.cs line 146

                        tree.MenuItems.Insert(0, new OdinMenuItem(tree, "None", 0));
    

    to:

                        tree.MenuItems.Insert(0, new OdinMenuItem(tree, Enum.GetName(typeof(T), 0).SplitPascalCase(), 0));
    
  2. Port25

    Updated, per Tor Vestergaard's comment about accounting for an undefined 0 value

    tree.MenuItems.Insert(0, new OdinMenuItem(tree, Enum.GetName(typeof(T), 0)?.SplitPascalCase() ?? "None", 0));
    
  3. Log in to comment