Search Issue Tracker
Duplicate
Votes
0
Found in
2022.3.59f1
6000.0.41f1
6000.1.0b9
6000.2.0a6
Issue ID
UUM-98769
Regression
No
UI Image batching breaks when the Image is nested in a Prefab and is offset on the Z-axis
Reproduction steps:
1. Open the attached “IN-95803.zip” project
2. Open the “SampleScene”
3. Open the “Frame Debugger” Window (Window > Analysis > Frame Debugger)
4. Enable the Frame Debugger
5. Search for “Canvas.RenderSubBatch” and observe its draw call value
6. From the Hierarchy, select any “Canvas” child GameObject
7. Modify its Z Position value from the Inspector to anything other than “0”
8. Observe the “Canvas.RenderSubBatch” draw call value in the Frame Debugger
Expected result: The draw call value remains “3” and batching does not break
Actual result: The value increases to “6” or higher (depending on which GameObject was selected in the 6th step) and batching breaks
Reproducible with: 2022.3.59f1, 6000.0.41f1, 6000.1.0b9, 6000.2.0a6
Reproducible on: Windows 11
Not reproducible on: no other environment tested
Notes:
- If all GameObjects have the same Z Position value (e.g. “1”) the batching still works correctly
- For example, if all GameObjects have a Z position of “0” except icon #4, then all the UI objects before #4 are batched together, then #4 is drawn and the elements after are batched together, resulting in 8 batches
- If the Prefab is modified so that individual Image GameObjects are offset on the Z axis, nothing batches at all resulting in 27 draw calls
- Could not reproduce with Image that is not in a Prefab
-
Resolution Note:
This issue is a duplicate of an already reported issue that was closed with the resolution "As Design". We will do our best to contribute to the documentation to clarify what is happening with batching and the Z property.
For convenience here is the resolution message from the other issue.
After investigating this further, we have determine that it's a long standing behaviour (10+ years) of the Canvas system. Let us try to explain the situation.
When Canvas elements have a Z value that is not zero, their rendering instruction is flagged as not being co-planar with the Canvas.
As the UI system iterates over the children in order, it sorts rendering instructions according to various parameters, including material and texture. When a non-coplanar object is encountered, it is forced to the end of the instruction list to make sure it renders after objects by being given a higher "depth".
When the sorted list is processed to build the actual batches, the fact that the instruction is not co-planar is not a reason to break the batch, as long as other requirements of batching are satisfied.
However, when using different materials in an interleaving fashion such as described here, the sorting algorithm prioritizes the depth over the material, to guarantee rendering order. As such, it is not possible to batch as you would expect.
We appreciate your input and please let us know if you have any other concerns or issues you would like to report in the future.
Duplicate of https://issuetracker.unity3d.com/product/unity/issues/guid/UUM-87152
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
- Unity CIL Linker fails on Player build when persistent listeners have "<" and ">" in their XML attribute names
- ”Lighting data asset ‘LightingData’ is incompatible with the current Unity version…” warnings are thrown when saving Indoors (URP) and Outdoors (URP) Scenes as Scene Templates
- [iOS] The screen blinks when transitioning from custom to Unity splash screen
- [macOS] ”Ignoring depth surface load action as it is memoryless” warnings are thrown when taking Game View Snapshot
- UI Builder Inspector scrolls back up when changes on an expanded but not fully displayed Inspector tab are saved
This is a duplicate of issue #UUM-87152