Search Unity

InspectorElement inside ListView

Discussion in 'UIElements' started by ung, Sep 13, 2019.

  1. ung

    ung

    Joined:
    Feb 22, 2015
    Posts:
    159
    Hi,

    I am trying to make a ListView use an InspectorElement for its children. What seems to be happening is that the inspector of the child object is rendered twice per item. This is happening inside an editor window where I am using uquery to retrieve the ListView and then set its properties using C#.

    Code:

    Code (CSharp):
    1. // Foo is a ScriptableObject
    2. var items = Resources.LoadAll<Foo>("");
    3.  
    4. var listView = this.rootVisualElement.Q<ListView>("list-view");
    5. listView.makeItem = () => new InspectorElement();
    6. listView.bindItem = (e, i) => ((InspectorElement) e).Bind(new SerializedObject(items[i]));
    7. listView.itemHeight = 100; // Just an arbitrary value for now
    8. listView.itemsSource = items;
    Foo has a custom uxml based editor with just a single label and the UIElements Debugger window shows that each InspectorElement has indeed 2 children of type TemplateContainer.

    My guess is that I am setting up the binding the wrong way but I am not sure how to fix this.
     
  2. ung

    ung

    Joined:
    Feb 22, 2015
    Posts:
    159
    I will add to that that I see the same thing happening even if I remove the custom editor for Foo or if I add the InspectorElement to the root visual element directly.
     
  3. ung

    ung

    Joined:
    Feb 22, 2015
    Posts:
    159
    I just found out that apparently this is a known bug in 2019.3 so I guess it's fine.
     
  4. antoine-unity

    antoine-unity

    Unity Technologies

    Joined:
    Sep 10, 2015
    Posts:
    102
  5. ung

    ung

    Joined:
    Feb 22, 2015
    Posts:
    159
    Yep that must be it, thanks :)