"CameraClearFlags.Nothing" does not work?

so i was recently looking into trying to make a camera not clear on each update. i went through documentation, and found this.
when applying it to my script (seen below) it doesn’t work.
i’m calling the function, but it doesn’t keep the deformations. am i doing something wrong?
thanks for the reply.

using UnityEngine;

public class cameraData : MonoBehaviour

private Camera cam;

void Awake()
    cam = GetComponent<Camera>();

public void DontClear()
    cam.clearFlags = CameraClearFlags.Nothing;


is this script on the main camera, if not, it wont find the camera
try finding main scene camera like this.
cam = Camera.main;

also if you have multiple cameras, the other ones will still be clearing

I’m not sure if you really understand what “CameraClearFlags.Nothing” really does. You almost never want to use this setting. It keeps everything as it is. That means the color as well as the depth buffer will stay untouched. Since the depth buffer isn’t cleared you most likely can’t draw anything unless it’s actually closer to the camera.

Keep in mind that not clearing the camera doesn’t mean the scene isn’t rendered. However as i said if the rendered geometry is further away than what is currently in the depth buffer nothing will be written at all.

On the other hand if you used shaders which do not write into the depth buffer (like most transparent shaders) the image would be overdrawn / blended every frame.

It’s not clear what you want to use this for, so we can’t suggest what you should do since we don’t know what you want to do.