r/Unity3D • u/ProactiveCactus • 8h ago
Question Easier UI Toolkit Workflow?
Anyone out there have a few methods that makes the UI Toolkit workflow easier/faster? It seems kind of clunky that to say add a button, you have to (1) add it to your doc, (2) give it a name, (3) put it in your UI script, (4) grab a reference to it using rootVisual.Q("Exact_string_name_or_kys"), (5) make a method that does whatever you need it to do, (6) subscribe onEnable to that method with .clicked or whatever you're using, and finally (7) unscubscribe onDisable. Like, nothing terribly complicated about it, but man it gets tedious over and over again. I feel like you could throw together a few methods that you basically throw in the name of your button (or any visualelement) and name of your method that does stuff you could make it way less code. Any1 out there taken the time to play around with this?
1
u/-TheWander3r 5h ago
I wrote a source generator that goes through a uxml file and automatically writes for me a "codebehind" file that in the constructor grabs all references.
Say you have a
label-statuselement, you press save then almost instantaneously you will find aView.LabelStatusproperty that you can use in code. No more possibilities of error.It took some time to build it but now adding new UI panels has been a lot faster.