Search Issue Tracker
By Design
Votes
0
Found in [Package]
0.5.7-preview, 0.10.0-preview
Issue ID
1216843
Regression
No
[UIElements] Incorrect Element Position when it is Absolute
How to reproduce:
1. Open the attached project
2. Open the UI Builder (Window->UI->UI Builder)
3. Open the NewUI.uss in UI Builder Window
4. Inspect the "Submit" Button's Position values
5. Open the "NewUI" Window (Window->NewUI)
6. Observe the opened Window
Expected result: There's a Button drawn in the bottom-right corner of the Window
Actual result: Button doesn't appear in the Window and needs to be offset, in order, to be seen
Reproducible with: 2019.2.20f1, 2019.3.0f6, 2020.1.0a22 (0.5.7-preview, 0.10.0-preview)
Couldn't test with: 2017.4.36f1 (Package Manages does not exist), 2018.4.17f1 (Script compilation errors)
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
- "Rendering Debugger" displays incorrect overdraw count when using "Unlit/Texture" shader
- Scene and Game views break when the Editor window is snapped with the Microsoft PowerToys
- Materials do not transfer texture when the "Shader" parameter is changed from "Unlit/Texture" to "Universal Render Pipeline/Unlit"
- [Linux][Vulkan] Crash when opening searchable dialog
- The "Shader error in 'AE/Leaves': "Undefined punctual shadow filter algorithm"" error appears when build completes on a specific project
Resolution Note:
Absolute position should not be used often as it comes with a lot of pitfalls like this. The UI Builder "canvas" area is flex-grow:1 by default, so absolute-positioned elements in the root of the UXML document are offset based on the full size of the canvas. But when you CloneTree(), the TemplateContainer produced containing all your UI in the UXML does not have flex-grow:1 so anything that was offset will not be wrongly offset.
But "solving" this is quite hard in the general case because we can't just switch all default TemplateContainers to flex-grow:1 because that will break a whole bunch of other use cases.
While the current workflow and UX can be improved to communicate this issue better when using Absolute position, this is by design. You can quickly fix this, use asset.CloneTree(rootVisualElement), instead of CloneTree(), which will avoid creating the TemplateContainer. Or, give your "root" element (which is a TemplateContainer) .style.flexGrow = 1.