How can i detect on runtime if a visual element has inline styles? and then reset back those to default

Hi there,

How do i detect on runtime what styles properties have inline styles or those styles were previously set on runtime with scropting. So i can then reset back to their ‘default’ state.

This information aalready appear in UiToolkit Debugger so i hope there is a way to do that on runtime too?

Thanks

To check if has an inline style set (using flexDirection as the example, but you can use any):

var hasInlineflexDirection = labelLine.style.flexDirection.keyword != StyleKeyword.Null;

And to set it:

labelLine.style.flexDirection = StyleKeyword.Null;

This is from some quick testing. After you set the inline value, keyword gets set to Undefined, so you might want to check that instead of != null, idk.

2 Likes

Also, don’t mix up StyleKeyword.Null with StyleKeyword.None. It is a frequent mistake of mine.

I would have to verify, but that check might not cover inline style assigned through uxml, but it definitely works for value set through code. Let us know if you need more support with this.

1 Like

Thanks for reply, I actually need this so i can use visualelements in pool, and reset them to default styles when returned, for classes, its easier as i can loop through classes and remove my own
but for inline styles, i had no idea, and thanks to Baste i got the answer (uStyleKeyword.Null )
Please let me know for above usecase, am i missing any other thing? Thanks