RTS style terrain changer.

Hello, Im making an RTS and theres a key problem, the buildings can go through the ground, I need to A) be able to flatten the terrain to suit the building B) cancel the placement of the object.

To flatten the terrain under the buildings at runtime, you'll need to use the undocumented terrain commands SetHeights and GetHeights. You can find more detailed information about how to use them here:

Modifying terrain height under a gameobject at runtime

If you need to make the action un-doable (within your game, not the editor), you'll need to first use GetHeights to sample the height date under the building area, and store the resulting height data in a temporary variable before flattening the ground. Then if the user wants to cancel/un-do the building placement, you can Destroy the building object, and re-set the terrain to how it was before by using SetHeights with the original stored height data.

Terrain Destruction allows you to deform terrain using a heightmap texture. If you use a flat texture, you can carve flat surfaces into the terrain.