The IMGUI emun property inside a IMGUIContainer and ListView work incorrectly.

I customize a Editor to implement my own CreateInspectorGUI. I add a ListView with each element is a IMGUIContainer. I find if there has any dropdown menu inside the IMGUIContainer, the inspector work incorrectly. If you change the dropdown menu, it seems the internal state is broken.

The code like this:

[CreateAssetMenu(fileName = "ExampleObj", menuName = "Test/ExampleObj")]
public sealed class ExampleObj : ScriptableObject
{
    [SerializeField]
    private Entry[] entries;

    public enum Option
    {
        A,
        B,
        C,
    }

    [Serializable]
    public struct Entry
    {
        public Option option;
        public string text;
    }
}

[CustomEditor(typeof(ExampleObj))]
public sealed class ExampleObjEditor : Editor
{
    public override VisualElement CreateInspectorGUI()
    {
        var entries = this.serializedObject.FindProperty("entries");
        var list = new ListView
        {
            reorderable = true,
            reorderMode = ListViewReorderMode.Animated,
            virtualizationMethod = CollectionVirtualizationMethod.DynamicHeight,
            showBorder = true,
            showBoundCollectionSize = false,
            showAddRemoveFooter = true,
            bindingPath = "entries",
            makeItem = () => new IMGUIContainer(),
            bindItem = (ve, index) =>
            {
                var imgui = ve as IMGUIContainer;
                imgui.onGUIHandler = () =>
                {
                    if (index >= entries.arraySize)
                    {
                        return;
                    }

                    var element = entries.GetArrayElementAtIndex(index);
                    var option = element.FindPropertyRelative("option");
                    EditorGUILayout.PropertyField(option);

                    var text = element.FindPropertyRelative("text");
                    EditorGUILayout.PropertyField(text);
                };
            },
            unbindItem = (ve, index) =>
            {
                var imgui = ve as IMGUIContainer;
                imgui.onGUIHandler = null;
            },
        };

        return list;
    }
}

I attach the BUG Demo project with Unity 2022.1.17f1. Open the project, select “Assets/ExampleObj.asset”. Then try to change some enum dropdown in the inspector.

8457602–1122464–BUG Demo.zip (21.5 KB)

I’m currently investigating. I can repro on my side. I’ll keep you updated.

I logged a defect for you. Looks like a certain event is not catched or works properly.

In 2021.3 the same happens for UI Toolkit Listview custom inspector that shows elements with EditorGUI.Popup.

Upon changing the popup value (when user mouse up), the element is auto selected and the list goes into re-order mode. The element does not snap to proper positions in the listview and sometimes the entire list becomes bugged. After inspector refresh it shows properly but still behaves as above.

@pierre_10 I see this is marked as fixed, will it make its way into the Unity 2022 LTS build as currently this is still present in 2022.3.9f1 LTS?

The problem still present in 2022.3.10f1, any idea when this fix will be added?
Ok so it seems to be just on a Blackboard when adding a IMGUIContainer with a dropdown in. Happens in 2022 and 2023 Editors.

If you are using IMGUIContainer inside UnityEditor.Experimental.GraphView, I found a simple workaround.
UnityEditor.Experimental.GraphView.Dragger stops propagation of mouse event so somehow IMGUIContainer can’t receive event.
Just register callback to IMGUIContainer for MouseDownEvent and MouseUpEvent and remove/add dragger.
You can register callback to contentContainer, but in this case dragging content area will not drag blackboard.