I have a set of color variables in :root in the root node stylesheet.
What I want to do, is to dynamically change these colors base on the current theme of the match (each match has it’s own color theme). Coudn’t find any documentation how to change these custom properties through code.
AFAIK, you can’t over-write these values at run-time. But what you can do is create multiple themes, each of which contains different definitions for these variables and then switch between them at runtime.
I’m sure there are quite a few ways to set this up depending on your needs, but for example you can do something like:
MainTheme.tss: The default theme in your panelsettings. Contains all of your regular stylesheets, which depend on var(--ui-color)
AltTheme.tss: Inherits from MainTheme, and includes AltStyle.uss
Then in code, you swap themes on your UIDocument(s), perhaps by loading them from Resources or something:
public class ThemeSwitcher : MonoBehaviour
{
public void OnSwitchThemeButtonPressed()
{
GetComponent<UIDocument>().panelSettings.themeStyleSheet = Resources.Load<ThemeStyleSheet>("AltTheme");
}
}
Oh I didn’t even know that there was a thing called theme . Thanks for the info @noirb . Definitely will make things a bit easier. But would be really good to be able to override these variables (custom properties) in runtime, the same as you can to in standard CSS.