We recently found a bug which implies a bad precedence when using cascading styles sheets. When you have a theme sheet for you entire application, with classnames like following “.test” which specify a “color: green;”, and you defined that, in a specific UXML and USS view, every Label are red, UI Toolkit pick the Label instead of the classname.
I think USS precedence is higher than TSS (just from my experience); but I usually find hard to override Unity’s theme styles (which is a TSS file?), usually throwing many selectors solves to override. I also believe there is a bug with precedence/selectors, or some undocumented rules. I, also find this confusing.
By default, every classname you want to override from the UnityDefaultRuntimeTheme (which is a .tss file) have higher priority. Because the default theme is loaded first, every style loaded after gains priority.
The architecture of our theme is a inherited style from the unity default one :
So, this is the “normal” load order :
1 - UnityDefaultTheme (which is including default)
2 - NebulaeDefaultTheme (our game runtime theme) which is loading “Global.uss” and then the TSS styles (because TSS files are USS files, you can modify the theme in your IDE)
3 - Files from the UXML template
But, even with this load order, selector precedence remains and if I declare a Label in the (3), and a .unity-label in the (2), the second one has priority.