{
  "id": "unity/physics-overlap-sphere-null",
  "signature": "NullReferenceException: Physics.OverlapSphereNonAlloc returned null results array",
  "signature_zh": "NullReferenceException：Physics.OverlapSphereNonAlloc 返回了空的结果数组",
  "regex": "NullReferenceException: Physics\\.OverlapSphereNonAlloc returned null results array",
  "domain": "unity",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "The results array passed to OverlapSphereNonAlloc is null or not initialized before calling the method.",
  "root_cause_type": "generic",
  "root_cause_zh": "传递给 OverlapSphereNonAlloc 的结果数组在调用方法之前为 null 或未初始化。",
  "versions": [
    {
      "version": "2020.3.48f1",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "2021.3.30f1",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "2022.3.10f1",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "The null check doesn't prevent the NullReferenceException from being thrown when accessing the uninitialized array in the method call itself.",
      "fail_rate": 0.95,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "The error is about the array being null, not its size; size is irrelevant if the array reference is null.",
      "fail_rate": 0.99,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "OverlapSphere allocates a new array each call, which may fix the immediate null issue but introduces GC pressure and doesn't solve the root cause of uninitialized array.",
      "fail_rate": 0.3,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Initialize the results array before the call: `Collider[] results = new Collider[10]; int count = Physics.OverlapSphereNonAlloc(center, radius, results);`",
      "success_rate": 0.98,
      "how": "Initialize the results array before the call: `Collider[] results = new Collider[10]; int count = Physics.OverlapSphereNonAlloc(center, radius, results);`",
      "condition": "",
      "sources": []
    },
    {
      "action": "Check if results is null before passing: `if (results == null) results = new Collider[10]; int count = Physics.OverlapSphereNonAlloc(center, radius, results);`",
      "success_rate": 0.95,
      "how": "Check if results is null before passing: `if (results == null) results = new Collider[10]; int count = Physics.OverlapSphereNonAlloc(center, radius, results);`",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "Initialize the results array before the call: `Collider[] results = new Collider[10]; int count = Physics.OverlapSphereNonAlloc(center, radius, results);`",
    "Check if results is null before passing: `if (results == null) results = new Collider[10]; int count = Physics.OverlapSphereNonAlloc(center, radius, results);`"
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://docs.unity3d.com/ScriptReference/Physics.OverlapSphereNonAlloc.html",
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.88,
  "fix_success_rate": 0.95,
  "resolvable": "true",
  "first_seen": "2023-09-18",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}