{
  "id": "unity/raycast-multiple-collider",
  "signature": "InvalidOperationException: Physics.Raycast query may hit the same collider multiple times if the collider is not set to",
  "signature_zh": "InvalidOperationException: 如果碰撞器未设置为，Physics.Raycast 查询可能会多次命中同一碰撞器",
  "regex": "InvalidOperationException: Physics\\.Raycast query may hit the same collider multiple times if the collider is not set to",
  "domain": "unity",
  "category": "runtime_error",
  "subcategory": null,
  "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.",
  "root_cause_type": "generic",
  "root_cause_zh": "当碰撞器有多个接触点或未配置 'QueryTriggerInteraction.Ignore' 或正确的层过滤时，RaycastNonAlloc 查询会为单个碰撞器返回重复命中。",
  "versions": [
    {
      "version": "Unity 2022.3",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "Unity 2023.1",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "Unity 2023.2",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "Triggers can still cause duplicate entries in non-alloc queries; the issue is about query filtering, not trigger state.",
      "fail_rate": 0.6,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "RaycastAll also returns duplicates; the problem is generic to all raycast methods when colliders have multiple shapes.",
      "fail_rate": 0.8,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Contact offset affects collision detection resolution, not raycast query deduplication.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "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);",
      "success_rate": 0.95,
      "how": "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);",
      "condition": "",
      "sources": []
    },
    {
      "action": "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);",
      "success_rate": 0.85,
      "how": "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);",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "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);",
    "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);"
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://docs.unity3d.com/ScriptReference/Physics.RaycastNonAlloc.html",
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.87,
  "fix_success_rate": 0.9,
  "resolvable": "true",
  "first_seen": "2024-01-10",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}