- Home /
Undo changes made on terrain's splatmap
Hello,
I have a script that changes automatically the splatmap of a terrain. I would like to be able to undo the changes made by this script through the Unity undo system.
Here is one of the code I've tried:
Undo.RegisterUndo(myTerrain.terrainData, "Automatic Paint - " + myTerrain.name);
ChangeMySplatMapData(myTerrain);
Does anyone know how to make it work? (I really would like to avoid Undo.RegisterSceneUndo because my scene is really heavy)
Thanks ;-)
Answer by ModLunar · Jul 16, 2017 at 03:17 AM
I ran into a similar issue with trying to record undo on my terrain's TerrainData before modifying the heights. For my issue, I found that the Undo.RegisterCompleteObjectUndo function worked, so maybe try that?
This worked for me too, thanks!
Undo.RegisterCompleteObjectUndo(terrain.terrainData, "$$anonymous$$odify Terrain");
Answer by gilley033 · May 16, 2013 at 05:11 PM
Still looking for an answer on this one. Registering the terrain data should work since the splat map, like the height map, is part of the terrain data; but it doesn't. Has to be a bug.
In the meantime, I guess you have to just implement your own solution. Save the splat map before changing it and create a button that reloads the saved map when you press it.
Undoing changes to the alphamap still isn't fixed with the new Undo system. It's obvious there is a way, or else Unity wouldn't be able to allow you to undo texture painting. Anyone have a clue?
I have this problem to... What I did, is creating my own undo, where you can save terrain splatmap (float[,,]) on the stack, and load when pressing a button