[2019.4.4f] ListView and ObjectField questions

Hi,

I have few questions about how to properly do things or how to do them at all when using ListView and ObjectField. Everything is happening in editor mode.

  1. Is it possible to specify an uxml driven item layout when binding a list within the ListView tag? Right now I’m loading the item xml and bind it manually on bindItem method for a a list.
  2. How to properly clean the list of objects binded to a ListView? It is sufficient to destroy each one in the itemSource?
  3. Can I bind using binding-path attribute and have in a back a List , T : SerializableObject ? I wasn’t able to do it. The only way it seem to work is using the itemsSource in the code.
  4. How can I specify the object type for an ObjectField in uxml? I remembered at some point there was a attribute and I was able to get it set using the full qualified name for an object but that property is gone now and or doesn’t seem to do the trick.
  5. Is there any way to have drag-drop for rearranging items functionality in the list or needs to be be implemented manually?

Thank you

We don’t have this capability right now. You have to do it in C#.

Not sure what you mean. You normally don’t bind objects to a ListView, you bind ListView to your source data (via itemsSource), which is a list of “things”. You can just set the itemsSource to null if you want to “unbind” the ListView from the data. You need to call Refresh() on ListView to visually reset the items.

ListView is indeed bindable via binding-path. But setting the binding-path is not the whole story. If you are inside a custom Editor (custom inspector) and are overriding CreateInspectorGUI(), then that should actually be the whole story and “just work”. If not, you need to call Bind() on some common root element (can be the ListView itself) with a SerializedObject to bind to (and that contains your List field).

In 2019.4 or earlier, there’s no way to set the type via UXML. In 2020.1 and newer, it’s the “type” attribute. Looks like this:

<ObjectField label="Object Field" type="UnityEngine.Object, UnityEngine.CoreModule" />

This is built-in in 2020.2 and newer but not in earlier version. It’s optionally enabled via ListView’s new “reorderable” attribute/property.

Hi Damian ,

Thank you for the answers. No worries for second point. I think I know the answer.

Bogdan