unity runtime_error ai_generated true

ArgumentException:Tilemap 位置 (x, y) 超出边界。有效范围为 (0, 0) 到 (width-1, height-1)。

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

其他格式: JSON · Markdown 中文 · English
90%修复率
87%置信度
1证据数
2023-04-12首次发现

版本兼容性

版本状态引入弃用备注
Unity 2020.3.0f1 active
Unity 2021.3.0f1 active
Unity 2022.3.0f1 active
Unity 2023.2.0f1 active

根因分析

尝试在 Tilemap 定义边界之外的位置设置或获取瓦片,通常是由于循环边界错误或动态调整大小。

English

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.

generic

官方文档

https://docs.unity3d.com/Manual/class-Tilemap.html

解决方案

  1. 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 }

无效尝试

常见但无效的做法:

  1. Manually resize the Tilemap in the Inspector by changing cell bounds 75% 失败

    Resizing may not account for all tiles placed at edges; the error occurs at runtime due to code logic, not bounds settings.

  2. Wrap the call in a try-catch to ignore the error 90% 失败

    This hides the symptom but does not prevent invalid positions, potentially corrupting tile data.