Search Issue Tracker
By Design
Votes
0
Found in
2020.3.41f1
2021.3.12f1
2022.1.21f1
2022.2.0b13
2023.1.0a16
Issue ID
UUM-18795
Regression
No
Camera clears the depth buffer when the clear flag option is set to don't clear
Reproduction steps:
# Open the user’s attached project (“My Project.zip”)
# Open the “Assets/Scenes/SampleScene.unity” Scene
# In the Hierarchy find both the “First (cube) Camera” and “Second (sphere) Camera” GameObjects
# Observe their Camera Components Settings ( i.e Clear Flags, Culling Mask, depth)
# Observe the “Test.cs” attached to the “RawImage” GameObject
# Enter Play Mode
# Compare the offscreen rendering to the Game View to see the differences
Expected result: The “Cube” and “Sphere” GameObjects will not overlap
Actual result: GameObjects "Cube" and "Sphere" overlap
Reproducible with: 2020.3.41f1, 2021.3.12f1, 2022.1.21f1, 2022.2.0b13, 2023.1.0a16
Reproducible on: Intel macOS 16
Note: The "Second (sphere) Camera" GameObject clears the depth buffer during off-screen rendering, causing the "Cube" and "Sphere" GameObjects to overlap.
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
- Red spots appear when Blending Lighting Scenarios using Adaptive Probe Volumes
- [Windows] About Unity Window needs to be opened twice to adapt to resolution
- NullReferenceException and temporary graph corruption after entering playmode if output node connection was changed
- Sprite Renderer with Animation does not reflect Sprite changes in the Scene when switching Mask Interaction
- User is redirected to a non-existing online documentation link when clicking on "?" help button inside Inspector window while Animator Override Controller is selected
Resolution Note:
The renderer can't know the two calls to Camera.Render are connected and allocates a different depth buffer. This is not the case with the main scene as the engine knows all the cameras before rendering and assigns them to the same stack.
A possible workaround is as follows
1) Create new render texture asset in the project
2) Duplicate First & second cam and set them up in the inspector to render to the render texture from (1)
3) Assing the render texture from (1) to the RawImage canvas object
Similar set-up can be achieved from script. Setting it up this way means unity will automatically set up the two cameras as part of a stack and render correctly to them every frame as part of the main update loop. This also doesn't need a script.
I hope this helps.