How to avoid object that has deep part clipping with terrain or plane?

Im making a building game, but when i have building like this

Its clipping with terrain like this

How to prevent or avoid building clipping like that?

What you are looking for is called “stencil buffer”. There are plenty of tutorials on this topic around, for example:

Using the stencil buffer is a solution, but you could also just use a depth mask shader. The only issue here would be that when you want to draw anything else in that hole, that you have to draw that content before the depth mask. Note the

 "Queue" = "Geometry-1"

which makes the depth mask geometry to render before the normal geometry. This shader simply renders into the depth buffer without rendering anything in the color / frame buffer. Therefore it “hides” everything that would be rendered afterwards, behind or inside that mesh. So this can effectively used to punch holes in things. Though as I said, you can’t render anything inside the hole after the mask has been drawn. So this is purely order based.