Intended use of Theme Style Sheet

Hi,
I would like to know a bit more about the intended use of Theme Style Sheet, because it seems I could load up all of my USS in a default Theme, instead of linking theme in various Uxml, which seems more convenient to me. What do you think ?
To give you a little bit of context I’m currently building a large menu system for a game with lot of USS file and a Color Palette switching system, so what you’re doing with the TSS asset seems very interesting to me.
I’d be happy to know the future development scheduled for this feature and some typical use case where the TSS might be handy.

My project is on Unity 2020.2.7

Thanks a lot !
Alex

Assuming 2021.2.0a10 or newer version of unity:

TSS files are asset files that are mostly regular USS files that are viewed as a distinct asset type by Unity and exist for management purposes more than anything – they are the starting point of your own definition of a theme, made of USS selectors and property & variable settings. Regular USS syntax and format applies to TSS files as well, but usually a theme file will contain references to other USS files via the @ import rule (not that @ import is also supported in USS files directly)

What you would need to do is create your own theme file (create->UiToolkit-> TSS theme file) that import the runtime theme (called default) and override all variables/styles that you want to change in that theme.

Alternatively, an asset is automatically generated at Assets/UI Toolkit/UnityThemes/UnityDefaultTheme.tss when adding the first UIDocument to your scene that would be used by default. You could modify it directly, but I recommend you copy/create a new one to be able to do some back and forth between the “default” and your custom asset if necessary.

Once that is done, you will need to reference your new theme in the “Theme Style Sheet” field of the Panel Settings inspector.

Hello! Just wanted to make a side note that on preview 14 of the UI Toolkit package (latest available right now) we’re not using Themes on the PanelSettings just yet. This is coming out on preview 15, and if you use Unity 2021.2 (without the package as it already contains all the code for Runtime) you can use it there as well.

The idea behind the Theme type being different from a standard Style Sheet type is to give the idea that this is all the common basic styles for the whole UI (think of setting the font that you use everywhere, the button backgrounds, etc). It also allows for easy management of styles and being able to assign a single Theme asset into the PanelSettings, instead of multiple smaller Style Sheets potentially.

1 Like

Sorry if this comes out as rude but, does that use case really warrant a new file type and the domain complexity and potential confusion it adds??

If a TSS is just a USS used in a particular way, just… Let people use USS in a particular way to achieve the same. The web has been doing the same for 25 years and they’re fine.

On a related note, I’ve noticed lately an explosion of settings files (specially for the runtime related stuff) and I really have to ask if all that overhead is necessary. Flexibility is important but so is simplicity and ease of use

Having a different file type also allows us to handle it differently in existing or upcoming tools and systems.

1 Like

My explanation was over simplified, that’s not the only reason. I can assure you we reflect on the necessity of creating new types when we do it, and consider multiple scenarios for developers before choosing a certain path. UI Toolkit is inspired by web technology but has its own specificities, naturally.

My guess is you’re talking about Panel Settings and Panel Text Settings, as well as font configuration files. Yes, those are necessary. If you’re used to UGUI, imagine the Panel Settings as the replacement for your Canvas and Canvas Scaler duo, but this time it exists as an asset and not as an instance in the Scene (or a Prefab if you will). The text stuff is similar to whatever already exists for TextMesh Pro, for example, to enable rich text, emojis, all the text capabilities.

2 Likes

Thanks a lot for your answers, it seems to fit our team needs. Just one quick question, do you advise to use it even though it is still hidden in the Debug mode of the Panel Settings ? From what I understand the reason why it is still hidden is to avoid users mistakenly remove the Default.uss, is there other reason why I should not use it ?
To avoid any problem I just added the Default.uss to all of my TSS files like so :

6976409--822800--upload_2021-3-26_9-12-46.png

It works well so I’m very tempted to use it.

6976409--822797--upload_2021-3-26_9-11-19.png

That’s exactly why we hid it, it wasn’t clear what the theme style sheet field was for and if you don’t do the right thing your UI will look broken or depending on what you’re using you won’t see anything at all. If your UI is working with the file you created I say go for it :sunglasses:

We hope to have a new preview out soon where the field won’t be hidden anymore!

Yes it works, except for one thing, now it seems I have the default hover and focus styles on all my buttons.
I was wondering, is there a way to have the Default.uss.asset as a regular Uss file ? So I can duplicate it, make my own and remove what I don’t need ?
Thanks a lot !

Unfortunately no, that file only comes as an asset. You can override those styles on your own USS though.

Ok I see, what I had to do to override the button focus and hover is to make a very specific selector :
Button.unity-text-element.unity-button
Which is strange because in the debugger the matching selector is only unity-button, but simply overriding that selector wasn’t enough so I’m curious if there are more rules applied than what is shown in the debugger.

Hello, just came across your post again and came to say that there was an issue with the Theme Style Sheet we distributed that was making it take priority over user generated rules, which has since been fixed in Unity 2021.2+ and is coming out with the next update of the UI Toolkit package. From your last message here, I suspect you ran into this bug.

Hi there. I tried to implement the UI toolkit with my project and the UI I created doesn’t seem to use ANY theme in runtime (lacks any styling except those I explicitly added for each element in UI builder). I tried following the steps mentioned above and created my own theme with Default style sheet. But as was mentioned above, there’s no Theme field in Panel Settings in Preview 14. Is there anything I can do about it or should I just ignore the package for now?

Themes for the PanelSettings are coming with preview 15, which we’re currently working on and should be out really soon. On Unity 2021.2 you already have Theme on the PanelSettings, but for 2021.1 and older you still need the package for Runtime UI. Thank you for your patience as we sort this out! :slight_smile:

Themes for the PanelSettings you say. Is there any other place I can apply my theme then?

Not at the moment, but what I meant to say is that even though Themes exist separate from their use in PanelSettings, their use in PanelSettings is coming with preview 15.

When is preview 15 coming?
I am waiting for it for several month now. Without it we can’t update our project above 2021.1.7 since in later versions the UIToolkit debugger is broken when preview 14 is installed.

We’re in the process of getting it out, we also want it to be published as soon as possible! Thank you for your patience :slight_smile:

Has the initial intention for Theme Stylesheets (tss) files still apply according to SimonDufour Jun30, 2020?
I am also wondering if there is an update to UI Builder Theme Tab “UnityDefaultruntimeTheme” and whether this theme can be renamed?

Thanks

What Simon said about Theme Style Sheets is still valid, if that’s the question.

UI Builder uses the name of the asset to populate that list, so you can call your Theme Style Sheet asset file whatever you want to appear on the UI Builder.

Not sure what you wanted about that bug report, it was not using the right package for Runtime UI Toolkit and it was invalid.