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 :wink:

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?

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.

You can fix : Unity Terrain System, Brush Can't Undo Solution - YouTube

Recently ran across this as well. Was making an editor script that alters the height, splatmaps, and holes of a terrain and wanted undo functionality.

In Unity 2021.3 I had to register the terrainData.alphamapTextures. Here’s what I did before any operations on the terrain…

Undo.IncrementCurrentGroup();
Undo.RegisterCompleteObjectUndo(terrain.terrainData, "Modify Terrain");
Undo.RegisterCompleteObjectUndo(terrain.terrainData.alphamapTextures, "Modify Terrain");

Unity documentation also mentions this currently under:

“alphamapTextures: Alpha map textures used by the Terrain. Used by Terrain Inspector for undo.”