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
- The Scene View becomes gray and "NullReferenceException" errors are thrown when attaching the Unity Editor process to RenderDoc
- Memory usage rapidly rises when changing colors in the color wheel
- Physically Based Sky's Horizon and Zenith Tint Color Selection Bars don't have immediate access to color pickers
- EmptyAdditionalLightShadowmapTexture leaks from memory when URP quality level is changed using QualitySettings.SetQualityLevel
- Referenced ScriptableObject field does not get updated and cannot be set to "None" when there are no Objects of that type
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.