Does UI Toolkit runtime UI currently support uGUI like scroll view but even better that it’s pooling by default that like u have 10000 items but it will auto recycle the 10 items when u keep scrolling instead just instantiate all the 10000 items which slow down performance significantly?
Hi!
We currently support vertical virtualization through using ListView.
Hope this helps!
(We also support virtualization for TreeView, MultiColumnListView & MultiColumnTreeView)
Hey there, could list view used with complex objects? We have a huge performance drop when listing multiple cards because each one has an image, text, buttons etc… So ideally we would want to reuse them while scrolling.
Thanks!
Hi @paolo-rebelpug ! Yes, the list view can be used with complex objects.
It exposes a makeItem
property that can be used to create the hierarchy for your complex object and a bindItem
property that can be used to assign the data.
If all of the items can use the same hierarchy, the two properties above are enough to make it work. If the items can have different hierarchies (i.e. you intend to support different types of data), then you can add your own pooling for the sub-hierarchies by using both bindItem
and unbindItem
.
Hope this helps!
Yes list view works fine with uxml objects as you’ve described, but note the virtualization mode. If all of your cards are the same then you can use fixed height virtualization & fixed item height on the listview, this will allow the listview to calculate when to recycle an item that just went “off-screen”, based on the current scroll position, and move it to the end of the items list.
If you see weird items popping in/out when they shouldnt then change those two fields and it should fix your issue. Note that due to the listview implementation you can’t use listview’s existing virtualization modes for a grid view afaik.
You can hold a UXML asset reference as a VisualTreeAsset in code. Grab your ListView instance using VisualElement.Q(“list-view-name”) and subscribe to listView.makeItem with a callback that instantiates your VisualTreeAsset - the new method, VisualTreeAsset.Instantiate() sometimes gives me issues so I’ll use VisualTreeAsset.CloneTree() instead if that doesnt work. ListView.destroyItem is the opposite callback.
Then subscribe to listView.bindItem - in this callback, you can grab the corresponding data model to bind to based on the visual element index (which gets passed to your callback by the lsitview) and populate your card’s visual element from there. ListView.unbindItem is the opposite callback but I’m not 100% on what causes it to fire - I don’t always see this event get invoked; usually as a workaround I will prepend some unbinding logic in bindItem.
Hope that helps.
Thanks this is really helpfull, I’ll give it a go!