How to avoid permanent changes to terrain

Hey,

I’m writing some procedurally generated things… and adding trees to terrain and so on in runtime.

Now… all the stuff I do to terrains while in runtime seems to “stick” permanently to the terrain object, which is ok when deployed, since I suppose you aren’t saving the data anyway… but while developing in the editor it’s VERY annoying.

Is there a way to avoid this? What if I Instantiate() the terrain stuff at start… will a new terrain data spawn in my assets?

Finally got it to work… you can use this script before doing anything procedural to your terrains (note there’s some stuff here specific to my project, like “Terrain” layer):

	private void CloneTerrain(Terrain t) {
		TerrainData dataClone = Instantiate(t.terrainData) as TerrainData;
		Debug.Log("dataClone has name " + dataClone.name);
		GameObject newTerrainObj = Terrain.CreateTerrainGameObject(dataClone);
		newTerrainObj.layer = LayerMask.NameToLayer("Terrain");
		newTerrainObj.transform.position = t.transform.position;
		newTerrainObj.transform.rotation = t.transform.rotation;
		Terrain newTerrain = newTerrainObj.GetComponent(typeof(Terrain)) as Terrain;

		newTerrain.treeDistance = t.treeDistance;
		newTerrain.treeBillboardDistance = t.treeBillboardDistance;
		newTerrain.treeCrossFadeLength = t.treeCrossFadeLength;
		newTerrain.treeMaximumFullLODCount = t.treeMaximumFullLODCount;
		newTerrain.detailObjectDistance = t.detailObjectDistance;
		newTerrain.heightmapPixelError = t.heightmapPixelError;
		newTerrain.heightmapMaximumLOD = t.heightmapMaximumLOD;
		newTerrain.basemapDistance = t.basemapDistance;
		newTerrain.lighting = t.lighting;
		newTerrain.castShadows = t.castShadows;
	}

Note that setting the terrainData on a Terrain did not seem to work - it kept its old terrain data in the inspector.