Search Unity

Feature Request Disable rewriting on a Per UXML basis.

Discussion in 'UI Toolkit' started by MoruganKodi, Sep 18, 2020.

  1. MoruganKodi

    MoruganKodi

    Joined:
    Feb 11, 2015
    Posts:
    79
    Would like an attribute which could stop UIBuilder/Generator from rewriting our UXML files on a per UXML file basis.

    Example:
    Code (XML):
    1.  
    2. <UXML xmlns:fw="Framework.UIElements" generator="false">
    3.      <!-- stop messing with my hand written uxml files kthnxbai -->
    4. </UXML>
    5.  

    Case 1: It replaces my namespace references:

    If I point to my own UIElements namespace...
    Code (XML):
    1. <UXML xmlns:fw="Framework.UIElements">
    2. <!-- ... -->
    3. </UXML>
    ...and reference a custom element:
    Code (XML):
    1. <UXML xmlns:fw="Framework.UIElements">
    2. <fw:Popup />
    3. </UXML>

    The Generator will replace it with `<Framework.UIElements.Popup>`, and then it becomes this,
    often adding `uie` and/or `ui` namespaces as well pointing to `UnityEngine.UIElements`, even though I am not using anything in that namespace.

    Code (XML):
    1.  
    2. <UXML xmlns:fw="Framework.UIElements">
    3. <Framework.UIElements.Popup />
    4. </UXML>
    5.  

    Case 2: It replaces <UXML>

    Additionally the generator keeps swapping out <UXML> with `<ui:UXML>`, which breaks any element below which uses a custom namespace, EG: `<fw:UIElement>`. Or if I wanted to use `<fw:UXML>, we are constantly forced back into the default UIElements namespace.


    Case 3: UIBuilder/UIToolkit rewrites it anyhow...

    If you create a new UXML layout, add your new custom as a component into that layout, edit your USS, and save a custom UXML containing your element- the UXML for your custom element gets rewritten anyhow, just for existing inside some other layout.




    Case 4: It replaces my resource paths

    If you want to use a resource `path` instead of source. It also keeps getting replaced.
    Code (csharp):
    1.  
    2. <Style path="UIElement/USS/Popup" />
    3.  
    It keeps getting replaced with
    Code (csharp):
    1.  
    2. <Style src="/Assets/Game/Resources/UIElements/USS/Popup.uss" />
    3.  
     
  2. uDamian

    uDamian

    Unity Technologies

    Joined:
    Dec 11, 2017
    Posts:
    1,231
    This is a long requested feature but unfortunately not a high priority for the time being. Worth noting that overriding the UXML is not something we implemented by choice (and therefore could add an "option" to disable it). It's the reality of the current capabilities of our UXML importer, which does not fully capture and retain exactly which tag was on which line. The UXML import process is lossy and the UI Builder only deals with and manipulates the already-imported UXML asset in memory (the VisualTreeAsset), not the text-based .uxml file. As such, when it comes time to save your changes back to disk, there's no way to know what came from where and the Builder is forced to regenerate the entire UXML text from the modified VisualTreeAsset in memory.

    The UI Builder does try its best to keep the UXML _equivalent_ compared to the original version. Nothing should "break" between saves, except for manually authored comments and formatting. Custom namespaces should be fully expanded and continue to work without the need for the namespace shortcuts in the root UXML tag. Same goes for src/path attributes continuing to use relative paths where appropriate. So any functional problems encountered after saving an existing UXML in the Builder should be reported as bugs - just not formatting changes.
     
  3. MoruganKodi

    MoruganKodi

    Joined:
    Feb 11, 2015
    Posts:
    79
    Is there no way to at least get rid of replacing relative `path` with absolute `src`?

    This is specifically the biggest issue for me, as you cannot store themes with resource relative paths that can simply be installed into any resource folder (because UIToolkit rewites it with absolute paths every time).
     
  4. uDamian

    uDamian

    Unity Technologies

    Joined:
    Dec 11, 2017
    Posts:
    1,231
    Sorry for the delay. We have a task to address this inflexibility. In the meantime, what I would suggest, at least for USS references that serve as "themes", is to apply them above the uxml asset being authored in UI Builder. This can either be a host UXML that simply includes the "main" UXML and is itself never opened in the UI Builder - or it can be just in C#.

    Note that we should have a more formal Theme StyleSheet asset coming in 2021.1, which will be a separate type assignable via the UI Toolkit runtime Panel Settings asset. These new Theme StyleSheets will automatically be added to the UI Builder's Theme toolbar menu for previewing (same as the current default themes).