Search Unity

UIBuilder generated styles

Discussion in 'UI Toolkit' started by StephanieRowlinson, Nov 19, 2019.

  1. StephanieRowlinson

    StephanieRowlinson

    Joined:
    Jul 23, 2014
    Posts:
    137
    I'm was messing about UIBuilder and just created a simple screen with a single a textfield on it at an absolute position and the text bolded. I saved it to UXML and USS files as prompted and then went to look at what was generated.

    To my surprise the UXML looks like this:
    Code (CSharp):
    1. <ui:UXML xmlns:ui="UnityEngine.UIElements" xmlns:uie="UnityEditor.UIElements">
    2.     <ui:TextField picking-mode="Ignore" label="Text Field" value="filler text" text="filler text" style="position: absolute; top: 238px; left: 70px; -unity-font-style: bold;">
    3.         <Style src="TextFieldWithLabel.uss" />
    4.     </ui:TextField>
    5. </ui:UXML>
    And the USS is empty. Is this intentional or just the consequence of this still being a preview package?
     
  2. M_R

    M_R

    Joined:
    Apr 15, 2015
    Posts:
    559
    you need to extract the style of the element (by default is inlined). or manually create the selector and style that
     
  3. StephanieRowlinson

    StephanieRowlinson

    Joined:
    Jul 23, 2014
    Posts:
    137
    Ah, found it.

    Second question: how do I use an already existing style sheet in it? Or if I can't yet, when is that planned to be added?
     
  4. M_R

    M_R

    Joined:
    Apr 15, 2015
    Posts:
    559
    from C#, there is an API (AddStyleSheet iirc) that you can use after you load the asset.
    from UI builder, I think is planned (but you can manually edit the xml to include the style)
     
  5. uDamian

    uDamian

    Unity Technologies

    Joined:
    Dec 11, 2017
    Posts:
    1,231
    As M_R mentioned, there is no support yet to (re)use an existing StyleSheet via the UI Builder. However, if you do change the path in the UXML <Style> tag (for at least the first root element) and reopen the UI Builder with the modified UXML file, the Builder will correctly use the existing StyleSheet going forward. It's just the initial setup which is not supported yet. And yes, we do have plans to fix this soon.
     
    StephanieRowlinson likes this.
  6. StephanieRowlinson

    StephanieRowlinson

    Joined:
    Jul 23, 2014
    Posts:
    137
    Thanks for the answers. :)

    I tried to load the style by editing the UXML and it works fine in my test panel, but I'm still not seeing the style applied in the UI Builder. Is this a bug I should submit?



    upload_2019-11-20_8-31-16.png
     
  7. uDamian

    uDamian

    Unity Technologies

    Joined:
    Dec 11, 2017
    Posts:
    1,231
    The UI Builder currently does not refresh after external file changes. It's a known problem. You should see the styles applied if you File>New and reload your UXML in the Builder (closing and reopening the Builder window is not enough)
     
    StephanieRowlinson likes this.