Hello there.
All I am interested in is runtime, not editor. What I want to achieve is ListView with bunch of buttons (or any VE at this point), depending on fetched data. I’ve already made my first binding with simple text to label (setting binding path in uxml and then veRoot.Bind(obj)) so I guess I know how it works. But… then I can’t build it because Bind is from UnityEditor.UIElements.
Imagine that I download some data from database (let’s say songs to choose from). How do I do the rest? Am I supposed to ListView.Add(new Button()) for each record fetched? How do I bind song’s name to button? Via code? Am I supposed to change text of buttons directly? I can’t do it via binding, can I? I am clearly missing something here.
/edit
I am not even sure if I am using these VisualElements correctly as I can’t even add VisualElements via code to ListView, only to ScrollView.
I was really looking forward to UI Toolkit because it is much easier to use than old GUI system. My game will be 100% UI based and I just wonder if this is the right way to go. I’d love to use Unity because then I can deploy it on android/iOS/Win/Linux at once where with WPF I can do it only for Windows.
Best regards.
Hi there. A couple of things to unpack.
Bind() is Editor-only because it and the rest of our bindings system relies (right now) on SerializedObjects and SerializedProperties - which are Editor-only concepts. We do not currently have a runtime binding solution. We are working on it.
As for ListView, ListView is a very different control from ScrollView. ListView virtualizes its contents. It means it creates only enough VisualElements as can physically fit within its content container (and not more) and as you scroll, it rebinds (recycles) those same elements with new data from its data backend (like a List). ListView is 100% runtime compatible. It has the concept of bindItem(), bit it’s not related at all to Bind() or the rest of our core binding system. It just means “bind this list item element to this data item in the data backend”. This is also why you cannot just add elements to ListView via Add(). ListView assumes full control over its internal elements.
To see an example of how to use ListView, go to the Window > UI Toolkit > Samples menu in Unity and find ListView.
PS: You really only need to use ListView if you think you’ll have a lot of items in the list (like, a lot more items than can be seen at any one time). If this is not the case, a simple ScrollView should be sufficient.
Is this still suppose to be true?
I have a UIElement getting data bound to it using Bind outside of the Editor and it seems to be working fine, in Playmode at least. (Using the UI Toolkit preview, ofc)
1 Like
Are bindings still Editor-only? Looked through some of the 2021 release notes. (I am still using 2020.)
What’s the best way to stay up to date on this?
2 Likes