Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Bug Bad selector precedence

Discussion in 'UI Toolkit' started by curtispelissier, Jan 5, 2023.

  1. curtispelissier

    curtispelissier

    Joined:
    Jul 26, 2019
    Posts:
    39
    Hello,

    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.

    Styles order:
    upload_2023-1-5_16-58-42.png

    Render in UI Builder:
    upload_2023-1-5_16-59-21.png

    This is not following the selector precedence system described in the documentation : https://docs.unity3d.com/2022.2/Documentation/Manual/UIE-uss-selector-precedence.html

    I think it's a bug because in CSS, classname have higher priority than types, regardless of their loading order in USS.
     

    Attached Files:

  2. TeorikDeli

    TeorikDeli

    Joined:
    Apr 6, 2014
    Posts:
    117
    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.
     
  3. curtispelissier

    curtispelissier

    Joined:
    Jul 26, 2019
    Posts:
    39
    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.
    upload_2023-1-9_12-37-3.png

    The architecture of our theme is a inherited style from the unity default one :
    upload_2023-1-9_12-37-57.png

    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.