- Home /
Strange Error With AlphaMapHeight
Hey there Unity, First off, the script I'm using is referenced here: http://answers.unity3d.com/questions/34328/terrain-with-multiple-splat-textures-how-can-i-det.html
I've had this non-game-breaking issue for the past couple of days. It all started when I added a fifth texture to my terrain. Maybe the code is only calculated for 4 textures or something? Anyway, I'm essentially just trying to get the texture underneath a tree when it grows to make sure it's growing on grass. Here is the code snippet that is giving me issues (though I will be happy to post full code).
I've googled and searched for hours and can't find any help here. I've tried putting in null checks and whatnot but that's the extent of my knowledge with getting alphaMap stuff.
// 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 );
And here is the error I'm getting:
ArgumentException: Invalid argument for GetAlphaMaps
TerrainDetector.GetTextureMix (Vector3 WorldPos) (at Assets/Assets2/TerrainDetector.cs:39)
TerrainDetector.GetMainTexture (Vector3 WorldPos) (at Assets/Assets2/TerrainDetector.cs:53)
TerrainDetector.CheckTexture () (at Assets/Assets2/TerrainDetector.cs:25)
Your answer
Follow this Question
Related Questions
Applying a Large Texture Map to a Terrain 1 Answer
Generated terrain heightmap is flipped from the alphamap. 1 Answer
Terrain Alphamap Transition? 0 Answers
Create alphamap from mesh 0 Answers
Update Terrain Texture at Object Location at runtime 0 Answers