- Home /
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
Answer by rajavamsidhar_gvs · Jul 21, 2015 at 11:40 AM
hi...! Once you check this thread it may help you link
That's not exactly what I need. I need to create a sort of listner that wait for a terrain edit event (terrain editor, no play mode/runtime) to avoid usless calculation that i want to do when terrain is edited.
Answer by xDevily · Jul 22, 2015 at 04:16 PM
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();
}
//.....