Search Issue Tracker
By Design
By Design in 2023.2.X
Votes
0
Found in
2021.3.24f1
2022.2.18f1
2023.1.0b15
2023.2.0a13
Issue ID
UUM-34855
Regression
No
Accessing the raw value of a USS variable fails when using customStyle.TryGetValue()
Reproduction steps:
1. Open project “IN-39634”
2. Open “Assets\IN-39634_Assets\Scenes\SampleScene”
3. Enter Play Mode
4. Observe the Game view
Expected result: text in the label displays "500ms"
Actual result: text in the label displays "Error loading value"
Reproducible with: 2021.3.24f1, 2022.2.18f1, 2023.1.0b15, 2023.2.0a13
Couldn’t test with: 2020.3.48f1 (compiler errors)
Reproducible on: macOS Ventura 13.2.1 (Intel)
Notes:
- Also reproducible in Standalone Player
- The stylesheet is referenced through the runtime theme, but explicitly referencing the stylesheet through the UXML file makes no difference either
Comments (1)
-
vallis_unity
May 04, 2023 07:58
Thanks for the reply. The stylesheet link vs theme link part is a bit of a red herring as I was trying it both ways in the repro to see if that made any difference to TryGetValue. There was no problem with the USS rule applying to the label, the issue was only with reading the value of the variable into code.
I've verified that doing the TryGetValue does indeed work in LateUpdate. Is there a better way to read the value of the USS variable into code? Firstly, it seems odd that a compile-time and project-wide constant fails to read at certain points within a frame. Secondly, it doesn't seem great to be grabbing the value as a string and then removing the "ms" part of the property. Is it possible to read the value using something like the TimeValue struct, which feels like it should be more appropriate for the value in question?
Many thanks!
Add comment
All about bugs
View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.
Latest issues
- Out-of-bounds memory access with multiple CanvasRenderers under a Canvas when using Mesh API
- Inspector tries to access file after it was deleted when the file was locked in Inspector window
- Changing Transform values in Search window Inspector loses focus while dragging and stopping mouse without releasing dragging action
- Saving changes on the dirty VFX Graph during the Play mode throws "The referenced script (Unknown) on this Behaviour is missing!" warnings
- VFX Graph Debug Info overlaps the "Initialize" block debug info by default
Resolution Note:
There was a first problem in the tss file as the reference to the stylesheet was missing. I fixed that using a drag and drop of the stylesheet and applying the result.
The styles are updated before the LateUpdate and before the UI is rendered. In the case submitted, style value were read before the first LateUpdate. By modifying his code, we can see that the value read during OnEnable, Start, Update are all invalid as the styles have not been calculated yet, and then they start being what the user expected.
Please note that if you set the stylesheet in the theme, it will be at the root of the panel directly, but if the stylesheet is referenced by the uxml, it will be applied on the corresponding template container (directly on the UIDocument.rootVisualElement). You will need to adjust your code accordingly. The UI Debugger is a good tool to verify that the styles are applied on the expected elements.
Resolution Note (2023.2.X):
There was a first problem in the tss file as the reference to the stylesheet was missing. I fixed that using a drag and drop of the stylesheet and applying the result.
The styles are updated before the LateUpdate and before the UI is rendered. In the case submitted, style value were read before the first LateUpdate. By modifying his code, we can see that the value read during OnEnable, Start, Update are all invalid as the styles have not been calculated yet, and then they start being what the user expected.
Please note that if you set the stylesheet in the theme, it will be at the root of the panel directly, but if the stylesheet is referenced by the uxml, it will be applied on the corresponding template container (directly on the UIDocument.rootVisualElement). You will need to adjust your code accordingly. The UI Debugger is a good tool to verify that the styles are applied on the expected elements.