Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Join us on Dec 8, 2022, between 7 am & 7 pm EST, in the DOTS Dev Blitz Day 2022 - Q&A forum, Discord, and Unity3D Subreddit to learn more about DOTS directly from the Unity Developers.
    Dismiss Notice
  3. Have a look at our Games Focus blog post series which will show what Unity is doing for all game developers – now, next year, and in the future.
    Dismiss Notice

(Overlay) Camera Stacking / Clear Depth Via Script

Discussion in 'Editor & General Support' started by Gullie667, Jun 11, 2021.

  1. Gullie667

    Gullie667

    Joined:
    Apr 21, 2021
    Posts:
    12
    In URP, overlay cameras have a 'Clear Depth' Toggle.
    How can this be set via script?

    It can be read from UnityEngine.Rendering.Universal.UniversalAdditionalCameraData.clearDepth but not set?!

    Thanks!
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    29,722
    Standard cameras have a clearFlags property on them. Are URP cameras different? Look in their API... it won't be at a global universal level, it will be at a per-camera level if it exists.
     
  3. Gullie667

    Gullie667

    Joined:
    Apr 21, 2021
    Posts:
    12
    The is a clear flag but it seems to be unrelated to the clear depth flag :/
     
  4. imajor

    imajor

    Joined:
    Aug 21, 2020
    Posts:
    1
    I think this is a bug. Indeed changing clearFlags won't affect Clear Depth. The way I workarounded this is that I manually created an overlay camera in unity editor, unchecked the Clear Depth field in the inspector, and then saved this object as a prefab. Later then instead of creating a new camera from script using the new operator, I just instantiated this prefab. It is a very dirty solution, but it works.