# InvalidOperationException: Physics.Raycast query may hit the same collider multiple times if the collider is not set to

- **ID:** `unity/raycast-multiple-collider`
- **Domain:** unity
- **Category:** runtime_error
- **Verification:** ai_generated
- **Fix Rate:** 90%

## Root Cause

A RaycastNonAlloc query returns duplicate hits for a single collider when the collider has multiple contact points or is not configured with 'QueryTriggerInteraction.Ignore' or proper layer filtering.

## Version Compatibility

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

## Workarounds

1. **Use 'HashSet<Collider>' to deduplicate hits after calling RaycastNonAlloc. Example: HashSet<Collider> hitColliders = new HashSet<Collider>(); foreach (var hit in results) hitColliders.Add(hit.collider);** (95% success)
   ```
   Use 'HashSet<Collider>' to deduplicate hits after calling RaycastNonAlloc. Example: HashSet<Collider> hitColliders = new HashSet<Collider>(); foreach (var hit in results) hitColliders.Add(hit.collider);
   ```
2. **Set 'QueryTriggerInteraction.Ignore' in the raycast call and use layer masks to exclude duplicate-prone colliders. Example: Physics.RaycastNonAlloc(ray, results, maxDistance, layerMask, QueryTriggerInteraction.Ignore);** (85% success)
   ```
   Set 'QueryTriggerInteraction.Ignore' in the raycast call and use layer masks to exclude duplicate-prone colliders. Example: Physics.RaycastNonAlloc(ray, results, maxDistance, layerMask, QueryTriggerInteraction.Ignore);
   ```

## Dead Ends

- **** — Triggers can still cause duplicate entries in non-alloc queries; the issue is about query filtering, not trigger state. (60% fail)
- **** — RaycastAll also returns duplicates; the problem is generic to all raycast methods when colliders have multiple shapes. (80% fail)
- **** — Contact offset affects collision detection resolution, not raycast query deduplication. (70% fail)
