Home > database >  Set camera Depth Texture to None via script
Set camera Depth Texture to None via script

Time:10-27

I'm instantiating a camera in my code:

GameObject go = new GameObject("Second Camera");
Camera cam = go.AddComponent<Camera>();

My question is: how to set Depth Texture as None in the code?

enter image description here

When I instantiate, it always starts with this Use Pipeline Settings option and I cannot change it no matter what I do. I tried cam.depthTextureMode = DepthTextureMode.None but nothing changes. How can I set this to None?

My main camera needs to draw the depth texture, so I don't think disabling the depth texture in the URP settings is an option.

CodePudding user response:

That property is coming from UniversalAdditionalCameraData class.

using UnityEngine.Rendering.Universal;

var data = go.GetComponent<UniversalAdditionalCameraData>();
data.requiresDepthOption = CameraOverrideOption.Off;

Setting requiresDepthTexture also works

data.requiresDepthTexture = false;
  • Related