# ArgumentException: TerrainData.SetAlphamaps - alphamap resolution does not match terrain data

- **ID:** `unity/terrain-alphamap-resolution-mismatch`
- **Domain:** unity
- **Category:** runtime_error
- **Verification:** ai_generated
- **Fix Rate:** 90%

## Root Cause

The alphamap (splatmap) texture passed to TerrainData.SetAlphamaps has a resolution that does not match the terrain's configured alphamap resolution (width and height), causing an array dimension mismatch.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| Unity 2021.3 | active | — | — |
| Unity 2022.3 | active | — | — |
| Unity 2023.1 | active | — | — |

## Workarounds

1. **Before calling SetAlphamaps, ensure the float array dimensions match the terrain's alphamap resolution: int width = terrainData.alphamapWidth; int height = terrainData.alphamapHeight; int layers = terrainData.alphamapLayers; float[,,] alphamaps = new float[height, width, layers]; Then populate and assign.** (95% success)
   ```
   Before calling SetAlphamaps, ensure the float array dimensions match the terrain's alphamap resolution: int width = terrainData.alphamapWidth; int height = terrainData.alphamapHeight; int layers = terrainData.alphamapLayers; float[,,] alphamaps = new float[height, width, layers]; Then populate and assign.
   ```
2. **If using a texture as source, read its pixels into a 2D array and resample to the correct resolution using bilinear interpolation before converting to a 3D float array.** (85% success)
   ```
   If using a texture as source, read its pixels into a 2D array and resample to the correct resolution using bilinear interpolation before converting to a 3D float array.
   ```
3. **Use terrainData.GetAlphamaps(0, 0, width, height) to retrieve the current alphamaps, modify only the necessary cells, and then call SetAlphamaps with the same dimensions.** (90% success)
   ```
   Use terrainData.GetAlphamaps(0, 0, width, height) to retrieve the current alphamaps, modify only the necessary cells, and then call SetAlphamaps with the same dimensions.
   ```

## Dead Ends

- **** — SetAlphamaps expects a 3D float array (float[,,]), not a Texture2D. Resizing a texture does not convert it to the correct data format. (95% fail)
- **** — 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% fail)
- **** — The error prevents alphamap updates, so terrain texturing will be incomplete or incorrect, leading to visual bugs. (90% fail)
