Editorscript: detect terrain modifications

Hi, I want to detect terrain changes made into the editor by a scrip that only works into the editor. For example I want to detect when i edit terrain height.

I tried doing this (but it doesn’t work):

void UpdateHeigh()
{
	if(oldTerrain == null)
	{
		oldTerrain = myTerrain.GetComponent<Terrain>().terrainData;
	}
	else
	{
		if(oldTerrain != myTerrain.GetComponent<Terrain>().terrainData)
		{
			Debug.Log("Terrain has changed");
			oldTerrain = myTerrain.GetComponent<Terrain>().terrainData;
		}
	}
}

Notes:

  • oldTerrain is a TerrainData variable
  • UpdateHeigh() is called into Update() function
  • myTerrain is a GameObject variable

hi…! Once you check this thread it may help you 1

I got a solution. It’s not exactly what i wanted to do but it is close enought.
My solution:
I’ve created a button into a custom editor that call the UpdateHeight() function. So when I need to call it, I simply press the button.

//.....
			if(GUILayout.Button("Update Height"))
			{
				script.UpdateHeigh();
			}
//.....