Restricting Enum choices in EnumField

In the traditional editor code, you can restrict Enum choices in an EditorGUILayout.EnumPopup by passing in a delegate method to the popup that tests each value, for example:

ItemCategory newCategory = (ItemCategory)EditorGUILayout.EnumPopup(new GUIContent("Category"), category,
                IsCategorySelectable, false);
        protected virtual bool IsCategorySelectable(Enum location)
        {
            ItemCategory candidate = (ItemCategory)location;
            return candidate!=ItemCategory.Special;
        }

In my custom editors, I use this to disable elements that don’t make sense for that particular item. The item still appears in the popup, but it is grayed out and unselectable.

I would like to find a way to do this using the EnumField in UIElements.

2 Likes

Anyone ? I need this too

This is not something we support at the moment. I would suggest using a Popup. You can pass in a list of the enums you want visible.

2 Likes

Maybe I misunderstood the question, but I wanted to ask, why can’t I have a special enum?
Then reassign the values