How to draw the new built-in array inspector with UI Toolkit?

For a while Unity started drawing serialized array in this style where there is no “Size” anymore and also array element is reorderable, with nice + - buttons, with hover highlight, etc.

I have my array elements PropertyDrawer load UXML to return in its VisualElement CreatePropertyGUI(SerializedProperty property). But I didn’t implement IMGUI code in OnGUI. It is not compatible, it seems the new list only wants to draw using IMGUI.

When I use PropertyField : VisualElement to draw the array serialized prop in UI Toolkit way, I get the old design instead though in exchange I can have children that draw using its VisualElement PropertyDrawer.

Is there any way to use the new list design in VisualElement and go “all the way” VisualElement? Or is it planned in the future that PropertyField : VisualElement will be forwarded to looks like IMGUI one in the future? In that case, I will keep the code displaying old style so it gets upgraded automatically in the future.

(I cannot use new IMGUIContainer(() => EditorGUILayout.PropertyField(timelines); }); because the children also wants to use VisualElement-based code loaded from UXML, and no IMGUI code.)

1 Like

I reported this 6-month ago and here is Unity’s response:

1 Like

Hi, any update on this? 2021.3 LTS is out now

Hi!
In 2021.3, the inspector will still generate an IMGUI-based hierarchy when a MonoBehaviour doesn’t have a custom editor associated with it. This means that by default, unless you create a custom editor and opt-in to have it generated in UI Toolkit, it will only use IMGUI all the way.

Your first image is probably the consequence of this: it is using the IMGUI version of the ReorderableList and so your UI Toolkit implementation will not be used. This is unfortunate. but for this case, you must implement both the IMGUI and the UI Toolkit version in your property drawer. If it can use UI Toolkit, it will do so, otherwise it will use the IMGUI path.

Starting in 2022.2, the inspector will generate UI Toolkit hierarchies by default, so it should help a lot. You might still need to keep two implementations for a while if there are custom editor/property drawers written in IMGUI.

That being said, the full parity ListView in UI Toolkit should be available in 2021.3.