Hi!
When I make changes to the terrains textures during runtime by changing the alphamaps, the changes are permanently saved onto the terrain (in the scene, not(!) only during runtime). I can’t image that this is supposed to work this way, but anyway, whether it’s a bug or a “feature”, is there a way that changes made to the terrains textures are reverted at the end of runtime?
Thanks in advance for any help!
EDIT:
Here’s the code, which simply retrieves the alphamap for a specific position and re-weights the first texture to 100%. The Flush in the end doesn’t seem to do anything, maybe deprecated!?
Terrain terrain = GameObject.Find("Terrain").GetComponent<Terrain>();
TerrainData terrainData = terrain.terrainData;
Vector3 terrainPos = terrain.transform.position;
// calculate which splat map cell the worldPos falls within (ignoring y)
int mapX = (int)(((worldPos.x - terrainPos.x) / terrainData.size.x) * terrainData.alphamapWidth);
int mapZ = (int)(((worldPos.z - terrainPos.z) / terrainData.size.z) * terrainData.alphamapHeight);
// get the splat data for this cell as a 1x1xN 3d array (where N = number of textures)
float[, ,] splatmapData = terrainData.GetAlphamaps(mapX, mapZ, 1, 1);
splatmapData[0, 0, 0] = 1;
splatmapData[0, 0, 1] = 0;
splatmapData[0, 0, 2] = 0;
splatmapData[0, 0, 3] = 0;
terrainData.SetAlphamaps(mapX, mapZ, splatmapData);
terrain.Flush();