I’m trying to make a simple custom editor for a script that has nothing but a list of custom objects I’ve made in C#. I’ve named the list “MyCustomObjects”, and I’ve made a UIDocument for a custom control to represent a single instance of one of these objects. I want to populate one of these custom controls for each object in the list inside a ListView on my custom inspector UIDocument. This is how I’m doing it:
[CustomEditor(typeof(MySpecialClass))]
public class MySpecialClass_editor : Editor
{
[SerializeField]
public VisualTreeAsset MyEditorTree;
[SerializeField]
public VisualTreeAsset MyCustomObjectTree;
public override VisualElement CreateInspectorGUI()
{
VisualElement myInspector = new VisualElement();
MyEditorTree.CloneTree(myInspector);
var listView = myInspector.Q<ListView>("MyCustomObjects");
listView.Clear();
listView.makeItem = MyCustomObjectTree.CloneTree;
return myInspector;
}
}
The issue is that it not only creates a custom control for all the items in the list, but it has an extra one at the beginning of the list, along with the following warning message in the console:
“Field type UnityEngine.UIElements.TemplateContainer is not compatible with ArraySize property “MyCustomObjects.Array.size”
UnityEditor.RetainedMode:UpdateSchedulers ()”
When I disable “Show Bound Collection Size”, it doesn’t insert an extra entry at the beginning, and the warning goes away, but I’m just curious what’s happening here? I feel like I’ve followed the example in the Unity documentation quite well. Unity - Manual: Bind to a list with ListView
Does the Unity documentation not do this if you follow it exactly??