UIBuilder generated styles

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:

<ui:UXML xmlns:ui="UnityEngine.UIElements" xmlns:uie="UnityEditor.UIElements">
    <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;">
        <Style src="TextFieldWithLabel.uss" />
    </ui:TextField>
</ui:UXML>

And the USS is empty. Is this intentional or just the consequence of this still being a preview package?

you need to extract the style of the element (by default is inlined). or manually create the selector and style that

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?

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)

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 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.

1 Like

Thanks for the answers. :slight_smile:

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?

5193621--516185--upload_2019-11-20_8-31-16.png

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)

1 Like