prevent runtime Terrain editing to change terrain file permanent on disk

I edit the terrain details(grass+flowers+co) via runtime.

(Use case: player can build stuff+place objects dynamic and i remove grass under specific objects).

Here is how i do it in code (abstract example):

terrain.terrainData.SetDetailLayer(0, 0, 0, details)

What happens is that the terrain data is permanent (not onyl runtime!) changed and the terrain file is also marked as changed in src control (as expected).

I found a “solution” with using 2 terrains: an “original”/“preset” never changed which detail data is copied into the changed one as preset, so i dont lose the initial detail values after changing them.

But it’s annoying the terrain changes permanent and the game also writes then to the file system which i want to avoid especially for consoles.

Is there a way to do this in runtime only? Maybe i can create a copy of the preset terrain so it only exists in memory in runtime?

Does someone know a way?

This will only happen in editor. In built games the assets are immutable on disk, but their in-memory representations might still be changeable.

That’s what you want. The TerrainData structure is complicated to fully clone and there are some open source things out there to help you. I cloned TerrainData in my destructible terrain example but I forget what all I copied exactly. It certainly wasn’t 100% of the TerrainData contents, like I didn’t do anything with trees or details.

My terrain damager in MakeGeo… look for the TerrainDataCloner class.

https://discussions.unity.com/t/681462/7

1 Like

Thank you!

When it’s only in editor i can live with it:) rather than implementing a complex solution which maybe cause unexpected bugs.

I tested i now for PC and the terrain is changeable at runtime in the build version and works like expected. I went trough all game file change dates and it indeed also didn’t change a file so the files seem to be immutable like you said.

I need to test on consoles if it also works like expected (changebale in runtime but does not change game files on disk). When it works, i will probably just swallow the pill and undo every time the terrain in src control after play testing in editor.