# ArgumentException: TerrainData.SetAlphamaps - 透明度贴图分辨率与地形数据不匹配

- **ID:** `unity/terrain-alphamap-resolution-mismatch`
- **领域:** unity
- **类别:** runtime_error
- **验证级别:** ai_generated
- **修复率:** 90%

## 根因

传递给TerrainData.SetAlphamaps的透明度贴图（混合贴图）纹理的分辨率与地形配置的透明度贴图分辨率（宽度和高度）不匹配，导致数组维度不一致。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| Unity 2021.3 | active | — | — |
| Unity 2022.3 | active | — | — |
| Unity 2023.1 | active | — | — |

## 解决方案

1. ```
   在调用SetAlphamaps之前，确保float数组维度与地形的透明度贴图分辨率匹配：int width = terrainData.alphamapWidth; int height = terrainData.alphamapHeight; int layers = terrainData.alphamapLayers; float[,,] alphamaps = new float[height, width, layers]; 然后填充并赋值。
   ```
2. ```
   如果使用纹理作为源，先读取其像素到2D数组，使用双线性插值重新采样到正确分辨率，然后再转换为3D float数组。
   ```
3. ```
   使用terrainData.GetAlphamaps(0, 0, width, height)获取当前的透明度贴图，仅修改必要的单元格，然后使用相同维度调用SetAlphamaps。
   ```

## 无效尝试

- **** — SetAlphamaps expects a 3D float array (float[,,]), not a Texture2D. Resizing a texture does not convert it to the correct data format. (95% 失败率)
- **** — While this can work, it alters the terrain's base settings and may affect performance or other scripts that depend on the original resolution. (60% 失败率)
- **** — The error prevents alphamap updates, so terrain texturing will be incomplete or incorrect, leading to visual bugs. (90% 失败率)
