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
- Required SpriteMask class (ID 331) is stripped when "Strip Engine Code" is enabled
- “Maximized serialized file backup not found” error is thrown when minimizing a window in a newly opened project
- Build stack trace contains invalid lines when building with IL2CPP using scripts with delegates containing generic types in the signature
- Entities Systems window has a “Show Full Player Loop” dropdown which does nothing when clicked after enabling “Show Full Player Loop”
- Entities Hierarchy Search “Show/Hide” button’s Lens Icon is blurry when the Editor is on an external monitor
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.