Search Unity

InspectorElement inside ListView

Discussion in 'UI Toolkit' started by dani-unity-dev, Sep 13, 2019.

  1. dani-unity-dev

    dani-unity-dev

    Joined:
    Feb 22, 2015
    Posts:
    174
    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. dani-unity-dev

    dani-unity-dev

    Joined:
    Feb 22, 2015
    Posts:
    174
    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. dani-unity-dev

    dani-unity-dev

    Joined:
    Feb 22, 2015
    Posts:
    174
    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:
    780
  5. dani-unity-dev

    dani-unity-dev

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