Weird rendering glitch when camera and canvas are different sizes.

I have a script that keeps the camera in the same aspect ratio on any computer. But the canvas still always fills up the whole screen. But when they’re different sizes a weird rendering glitch happens where something in the canvas is rendered, but stays there indefinitely unless something is rendered above it.
Here’s a gif of what it looks like:

Does anyone have a good solution to fix this? It’s not game breaking or anything but would be nice without it. Thanks for the help!

You have probably changed the camera’s viewport to keep the aspect ratio, right? That means it keeps the rest of the screen untouched. Which means, nothing is clearing that part of the screen to a ‘defaut color’ - which means anything that’s rendered there, stays there (sometimes causing flickering due to the double/triple buffering). Then, your canvas is rendered over that part of the screen, also not overwriting the background.

The solutions here would be: Clear the whole screen to a default color somehow; for example, using another camera (that only clears the screen and renders nothing, and does it before the main one), or having an opaque background in your canvas.

Try setting clear flags on the camera. It might not help though