Skip to content

Instantly share code, notes, and snippets.

@unitycoder
Created March 16, 2016 14:18
Show Gist options
  • Select an option

  • Save unitycoder/3babe46f5375cfee2a1b to your computer and use it in GitHub Desktop.

Select an option

Save unitycoder/3babe46f5375cfee2a1b to your computer and use it in GitHub Desktop.
Modify TerrainData in editor runtime, without saving to terrain file
Q) test runtime adjustments to Terrain Data in the Unity Editor without writing to actual terrain file?
A) Instantiate() the TerrainData object to get an in-memory copy, then modify that?
theTerrainData = Terrain.activeTerrain.terrainData;
theTerrainData = TerrainData.Instantiate(theTerrainData);
Terrain.activeTerrain.terrainData = theTerrainData;
Terrain.activeTerrain.Flush();
@Eldoir

Eldoir commented Aug 9, 2017 •

Copy link
Copy Markdown

Hello,
When I came to your script, I felt close to the solution of my problem.
But it appears that it's not completely working.
What I'm trying to do is rotating a terrain in runtime, then I want the terrain to get back to its original rotation when I quit the app.

So I'm looking for the following algorithm :

  • Copy ("clone") the Terrain Data
  • Rotate that copy
  • When quitting, the copy is automatically destroyed, so the terrain should get back to its original data.

The last step seems bugged: I find myself with a blend of the original terrain, and the modified copy. Everything is back except the splat map.
I was hoping for your code to solve this, but it doesn't change anything.
I heard about the fact that the TerrainCollider.terrainData must be changed as well. But that doesn't work either.

Do you have an idea about what's going on... ?
Thanks in advance !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment