Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

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

Discussion in 'UI Toolkit' started by watsonsong, Sep 22, 2022.

  1. watsonsong

    watsonsong

    Joined:
    May 13, 2015
    Posts:
    555
    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:
    Code (CSharp):
    1.  
    2. [CreateAssetMenu(fileName = "ExampleObj", menuName = "Test/ExampleObj")]
    3. public sealed class ExampleObj : ScriptableObject
    4. {
    5.     [SerializeField]
    6.     private Entry[] entries;
    7.  
    8.     public enum Option
    9.     {
    10.         A,
    11.         B,
    12.         C,
    13.     }
    14.  
    15.     [Serializable]
    16.     public struct Entry
    17.     {
    18.         public Option option;
    19.         public string text;
    20.     }
    21. }
    22.  
    23. [CustomEditor(typeof(ExampleObj))]
    24. public sealed class ExampleObjEditor : Editor
    25. {
    26.     public override VisualElement CreateInspectorGUI()
    27.     {
    28.         var entries = this.serializedObject.FindProperty("entries");
    29.         var list = new ListView
    30.         {
    31.             reorderable = true,
    32.             reorderMode = ListViewReorderMode.Animated,
    33.             virtualizationMethod = CollectionVirtualizationMethod.DynamicHeight,
    34.             showBorder = true,
    35.             showBoundCollectionSize = false,
    36.             showAddRemoveFooter = true,
    37.             bindingPath = "entries",
    38.             makeItem = () => new IMGUIContainer(),
    39.             bindItem = (ve, index) =>
    40.             {
    41.                 var imgui = ve as IMGUIContainer;
    42.                 imgui.onGUIHandler = () =>
    43.                 {
    44.                     if (index >= entries.arraySize)
    45.                     {
    46.                         return;
    47.                     }
    48.  
    49.                     var element = entries.GetArrayElementAtIndex(index);
    50.                     var option = element.FindPropertyRelative("option");
    51.                     EditorGUILayout.PropertyField(option);
    52.  
    53.                     var text = element.FindPropertyRelative("text");
    54.                     EditorGUILayout.PropertyField(text);
    55.                 };
    56.             },
    57.             unbindItem = (ve, index) =>
    58.             {
    59.                 var imgui = ve as IMGUIContainer;
    60.                 imgui.onGUIHandler = null;
    61.             },
    62.         };
    63.  
    64.         return list;
    65.     }
    66. }
    67.  
    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.
     

    Attached Files:

  2. pierre_10

    pierre_10

    Unity Technologies

    Joined:
    Apr 1, 2016
    Posts:
    33
    I'm currently investigating. I can repro on my side. I'll keep you updated.
     
  3. pierre_10

    pierre_10

    Unity Technologies

    Joined:
    Apr 1, 2016
    Posts:
    33
  4. AlexFCL

    AlexFCL

    Joined:
    Mar 27, 2013
    Posts:
    17
    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.
     
  5. blueteak

    blueteak

    Joined:
    Feb 19, 2013
    Posts:
    139
    @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
    ?
     
  6. Gustave

    Gustave

    Joined:
    Nov 16, 2012
    Posts:
    2
    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.
     
    Last edited: Oct 20, 2023