Search Issue Tracker
By Design
Fixed in 2022.1.X
Votes
0
Found in
2022.1.0b4
Issue ID
1397453
Regression
No
[UI Builder] UI element properties assigned via UI Builder can't be accessed from script
Steps to reproduce:
1. Open attached project (test-uitoolkit.zip)
2. Open SampleScene
3. Notice there's 2 buttons in the scene - one red, one green. Both added via UI Builder
4. Enter play mode
5. Check the console
Expected result: both buttons should have their background colors and tint colors printed. Height of the button should be printed as well.
Actual result: all colors are returned as black (or RGBA values all 0). Height is also returned as null.
Note: If I first assign a value to that property via script, then it starts to work fine. So seems like stuff created via UI builder is somehow not initialised at runtime.
Reproduced with: 2022.1.0b4
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
- Opening Terrain Prefab in Prefab Editing Mode throws "NullReferenceException" error
- [Search] Dragging query pills put them behind the search text field
- A CustomPropertyDrawer that returns a PropertyField for a property named the same as a child field will not render all child fields
- Graphics Settings shows default values instead of the real values in the Rendering Debugger when Volume.profile is assigned via script
- Deleting multiple Tags throws “NullReferenceException”, and "Retrieving array element that was out of bounds" errors when holding the Enter key
Resolution Note (2022.2.X):
By design, to get inline styles set in the UI Builder you need to use resolvedStyle instead of style. Also, on Start of a MonoBehaviour the layout has not being calculated yet, so to be able to get an element's height it is necessary to wait until the first GeometryChanged event.