- Home /
Clipping object behind colliders
How might I clip an object that is behind another objects collider, but the object with a collider doesn't have a mesh renderer? Like an invisible box that clips objects behind it normally as if it was visible?
I hope this is clear enough, thanks!
Answer by Bunny83 · Sep 29, 2017 at 10:33 PM
Colliders have no relation to any rendering.
What you can do is use a mesh renderer with the depth mask shader. It doesn't render anything into the color buffer but only into the depth buffer.
This is working very well after some modifications. The only issue I had was that when the camera (and this only happened in game view, not scene) had the skybox as its clear flag, it caused it to leave graphic imprints on the objects masking the normal objects. But I solved this by setting it to Solid Color, and making a fake skybox around the camera with a cube (everything else caused the skybox to look weird, so I don't know what object is best for faking a skybox around the camera). And then tada! It works so thank you! I'm very new to shader writing in Unity so it's taking a bit to get used to and understand everything I can do.