How do I make terrain adapt to gameobject?

Hello everyone. In my game, you can build buildings. They are placed on the terrain. The problem is that my terrain is not flat, which means that when building a building, half of this building may hang in the air (see the example in image 1). How do I make my terrain adapt to the constructed buildings (example in image 2)?

Matching terrain heights to a collider:

In your case I’d make an invisible collider around the building base and use the code above to drive the terrain right up to it.