Custom Property Drawer - no selection field is clickable

I’ve run into an issue and I don’t know if its a bug or something wrong with my code.
But basically I cannot click or expand any selection fields that are not generated as children in a property field.
This happens with Popups, Foldout and Foldout Header Groups. Clicking on them does nothing.
I really don’t know what I’ve done wrong here:

[CustomPropertyDrawer(typeof(Criteria))]
    public class CriteriaPropertyDrawer : PropertyDrawer
    {
        public Type[] _criteriaTypes;
        public string[] _criteriaTypeNames;

        public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
        {
            return EditorGUI.GetPropertyHeight(property, label);
        }

        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            EditorGUI.BeginProperty(position, label, property);
            EditorGUI.PropertyField(position, property, label, true);
            position.y += EditorGUI.GetPropertyHeight(property);
            GetCriteriaList();
            EditorGUI.BeginChangeCheck();
            EditorGUI.indentLevel++;
            int index = EditorGUI.Popup(position, "Criteria Type", -1, _criteriaTypeNames);
            if (EditorGUI.EndChangeCheck())
            {
                Debug.Log($"Chosen index {index}");
            }
            EditorGUI.indentLevel--;
            EditorGUI.EndProperty();
        }

        private void GetCriteriaList()
        {
            if (_criteriaTypes == null)
            {
                _criteriaTypes = AppDomain.CurrentDomain.GetAssemblies()
                    .SelectMany(a => a.GetTypes())
                    .Where(t => t.IsClass && !t.IsAbstract && t.IsSubclassOf(typeof(Criteria)))
                    .ToArray();

                _criteriaTypeNames = _criteriaTypes.Select(t => t.Name).ToArray();
            }
        }
    }

I’m on Unity 2021.2.7f1

Well this is interesting. If I put it this way around it is now clickable but the popup options are displaying in an odd place. This seems like some sort of odd interaction between Popup and PropertyField.

Issue was that the popoup rect was using the property’s position height and not a single line height.

            Rect popupRect = new(position.x, position.y, position.width, EditorGUIUtility.singleLineHeight);

            int selection = EditorGUI.Popup(popupRect, popupLabel, index, _criteriaTypeNames);
1 Like