# ArgumentException: Tilemap position (x, y) is out of bounds. Valid range is (0, 0) to (width-1, height-1).

- **ID:** `unity/tilemap-cell-position-out-of-bounds`
- **Domain:** unity
- **Category:** runtime_error
- **Verification:** ai_generated
- **Fix Rate:** 90%

## Root Cause

Attempting to set or get a tile at a position outside the Tilemap's defined bounds, often due to incorrect loop boundaries or dynamic resizing.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| Unity 2020.3.0f1 | active | — | — |
| Unity 2021.3.0f1 | active | — | — |
| Unity 2022.3.0f1 | active | — | — |
| Unity 2023.2.0f1 | active | — | — |

## Workarounds

1. **Check bounds before accessing: if (tilemap.cellBounds.Contains(new Vector3Int(x, y, 0))) { tilemap.SetTile(new Vector3Int(x, y, 0), tile); }** (90% success)
   ```
   Check bounds before accessing: if (tilemap.cellBounds.Contains(new Vector3Int(x, y, 0))) { tilemap.SetTile(new Vector3Int(x, y, 0), tile); }
   ```
2. **Use tilemap.HasTile(x, y) to verify existence before operations: if (tilemap.HasTile(new Vector3Int(x, y, 0))) { // proceed }** (85% success)
   ```
   Use tilemap.HasTile(x, y) to verify existence before operations: if (tilemap.HasTile(new Vector3Int(x, y, 0))) { // proceed }
   ```

## Dead Ends

- **Manually resize the Tilemap in the Inspector by changing cell bounds** — Resizing may not account for all tiles placed at edges; the error occurs at runtime due to code logic, not bounds settings. (75% fail)
- **Wrap the call in a try-catch to ignore the error** — This hides the symptom but does not prevent invalid positions, potentially corrupting tile data. (90% fail)
