Modify Terrain heigth at runtime only

I’m trying to get the hang of the “Terrain” tool in Unity, and I want to be able to manipulate terrain data to modify it at runtime.

I have a game object that I place somewhere on my terrain, and when the game is running, I would like to create a hole in the terrain at the location of this game object (the goal being, of course, to randomize the placement of the gameobject).

My attempts so far have led me to two questions:

  1. How do you change the height of a region at runtime? I’ve done several tests so far, but I don’t observe any changes in my terrain when I run it.
  2. I’ve seen in some tutorials that terrain modifications at runtime are saved to disk, meaning the terrain never returns to its initial state. How can we avoid that and restore the terrain to its original state when exiting play mode?

So, if anyone has tackled these issues with this tool before, I would be grateful for any advice :slightly_smiling_face:
Thanks

Terrain damager in MakeGeo:

Contains both code to clone the heights first (so the asset on disk isn’t changed), and code to smoosh the ground down.

Bonus: also has code to lift and lower the terrain so there is “foot room” to go lower, even if your internal terrain is completely flat.

I don’t know anything about holes in Unity terrain; when I wrote the above, holes were not possible. If they are, then perhaps the code above and the current API can guide you.