# InvalidOperationException: 如果未将碰撞器设置为 QueryTriggerInteraction.Ignore，Physics.Raycast 查询可能会多次击中同一碰撞器

- **ID:** `unity/physics-query-hits-self`
- **领域:** unity
- **类别:** runtime_error
- **验证级别:** ai_generated
- **修复率:** 91%

## 根因

当碰撞器是触发器且 QueryTriggerInteraction.UseGlobal 设置时，Physics.RaycastNonAlloc 调用会返回重复命中，导致数组溢出。

## 版本兼容性

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

## 解决方案

1. ```
   Set QueryTriggerInteraction.Ignore in the RaycastNonAlloc call to ignore trigger colliders.
   ```
2. ```
   Use Physics.RaycastAll instead and deduplicate hits by collider instance ID.
   ```

## 无效尝试

- **** — The error occurs because the same collider is hit multiple times, not because the buffer is too small. (90% 失败率)
- **** — Changing isTrigger alters collision behavior and may not be acceptable for the game design. (70% 失败率)
