Hello!
I’ve been a fan of UI Toolkit for a while and have always used it by defining fields and creating the VisualTree through a script. However, I’m taking on a new project and designing a larger interface with many tabs (>10) and VisualElements within each tab (>10) that would be cumbersome to design through code, so I’ve given a chance to design it through the UI Builder.
I’ve found it a bit odd, as sometimes it can be very laggy, although disabling the live reload option on the Game window helped a bit. Anyways, I’ve completed the design fairly well and loved to use USS, as it helps standardizing my code.
The problem I’m having right now is that I don’t think I understood the purpose of UI Builder correctly. I’ve created a main tab UXML file and different UXML files for each tab, so that I could instantiate them when a button inside the main tab was clicked. However, I’m getting frustrated by discovering that there doesn’t seem to be a clear way to simply assign a behaviour to a button. For example: if I were to assign an event to a button on the main tab that triggered the opening of another tab next to it (it is a side menu), I’d have to first query all buttons in the main tab and register them to an event handling function to discern what’s going on and opening the corresponding tab. This gives me a couple of problems:
-
Polling a hierarchy of elements trying to match it to a specific button name is not what I was looking for, so I guess that the purpose of UI Builder and UXML is to actually build generic interfaces, not specific ones as I was expecting.
-
If I were to open a tab from the main one, then I’d have a few options that could be toggled or not. If one of them is toggled, to know which one it was, I’d have to poll all elements from the tab that was opened from the main one, register them to events and when it was triggered, I’d have to sort which toggle was clicked to know which method to execute, which is very cumbersome.
So my question is: why would I use UI Builder if I have to query all elements from the window in a script to get any information from it? This is why I think I understood it’s purpose wrong. Maybe if there are few buttons this would be useful, but with over 100 buttons, it gets very complicated. I guess that with bindings I could display data on it, but to input behaviours such as method triggering and etc, I guess it’d be a lot of trouble to go through, right?
Cheers!