- Home /
The question is answered, right answer was accepted
terrainData.SetAlphamaps trouble.
I am making a prosedualy generated terrain and am trying to apply textures when a point is at a elevation point. I have two textures in the terrain paint system and am trying to apply it to the terrain if a point is above a height.
for (int x = 0; x < terrain.terrainData.heightmapWidth; x++) {
for (int y = 0; y < terrain.terrainData.heightmapHeight; y++) {
if (pointMap [x, y] > 0.5f) { //pointMap is a float[,]
alphaMap [x, y, 0] = 0;
alphaMap [x, y, 1] = 1;
} else {
alphaMap [x, y, 0] = 1;
alphaMap [x, y, 1] = 0;
}
terrain.terrainData.SetAlphamaps (x, y, alphaMap);
}
}
So far it crashes the editor. If it didn't crash would it work and how do i stop it from crashing. Or do i have to set the splat-maps by code instead of manually in the editor?
It seams like it is trying to do something but the editor crashes over and over if i run the code. Am I doing this correctly? I am on a tight schedule.
Answer by AlucardJay · Aug 01, 2016 at 06:11 PM
Move line 10 out of the for-loops. You only want to set the alphamaps after the whole alphaMap array has been populated.
for( .... {
.......
}
terrain.terrainData.SetAlphamaps (0, 0, alphaMap);
scripting reference : http://docs.unity3d.com/ScriptReference/TerrainData.SetAlphamaps.html
I will try that. What would i put in the x and y values then. Or are those for offsets?
I found out that it is just offsets and i can put in values of 0
thank you and i hope other people find this helpful also.
Oops, sorry about that. Glad you found how to fix it. I have edited the answer correctly and added the scripting reference for future readers.
Follow this Question
Related Questions
Splatmap performance question 2 Answers
heightmap resolution and terraindata.getalphamaps 0 Answers
Torch Script Error - Unity crashes 1 Answer
How to use splat maps with materials instead of 2D Textures? 0 Answers
Terrain alphamap fade 1 Answer