- Home /
How to reset terrain alpha maps in runtime
The title explains it all, is there a way to reset a terrain's alpha map in runtime (reset the terrain 'paint')?
Answer by clunk47 · Sep 22, 2013 at 12:01 AM
Look under variables and functions inside the Unity Script Reference for: TerrainData. You can tweak all of these via script, therefore at runtime :)
I already looked over that, but it's quite ambiguous about terrain. When I tried to use alphamapSet it crashed my game.
The answer is in the link that @syclamoth gave you. http://docs.unity3d.com/Documentation/ScriptReference/TerrainData.SetAlphamaps.html
In your map variable, the last number should be the amount of layers, or textures you have painted on the terrain. To reset all paint to zero, here's an example of how to do this if you have a single paint layer, or texture.
using UnityEngine;
using System.Collections;
public class Example : $$anonymous$$onoBehaviour
{
public Terrain t;
float[,,] map;
void Awake()
{
map = new float[t.terrainData.alphamapWidth, t.terrainData.alphamapHeight, 1];
t.terrainData.SetAlphamaps(0, 0, map);
}
}
This is about the best constructive advice I can give.
Thanks! Based on what you said I did a bit of tweaking and got it working!
void RunGen_Clear(){
float[,,] map = new float[terrain.terrainData.alphamapWidth, terrain.terrainData.alphamapHeight, 25];
for (int y = 0; y < terrain.terrainData.alphamapHeight; y++) {
for (int x = 0; x < terrain.terrainData.alphamapWidth; x++) {
map[x, y, 0] = 1;
}
}
terrain.terrainData.SetAlphamaps(0, 0, map);
}
Glad that I as well as @syclamoth were able to sort this out for you. Any comments / answers that helped you resolve your concern definitely deserve a thumbs up. +1 for posting your solution. Happy Developing :)
Your answer
![](https://koobas.hobune.stream/wayback/20220613114601im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Distribute terrain in zones 3 Answers
perlin noise terrain is spikey 0 Answers
Multiple Cars not working 1 Answer
Instantiated Objects not Following Perlin Noise 0 Answers
Scaling and rotaion of terrain trees 1 Answer