{
  "id": "unity/ui-canvas-raycaster-null",
  "signature": "NullReferenceException: CanvasRaycaster: No camera found for canvas that is set to Screen Space - Overlay",
  "signature_zh": "NullReferenceException: CanvasRaycaster: 设置为屏幕空间-叠加的 Canvas 未找到相机",
  "regex": "NullReferenceException: CanvasRaycaster: No camera found for canvas that is set to Screen Space - Overlay",
  "domain": "unity",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "A Canvas in Screen Space - Overlay mode requires a camera to render raycasts, but the event camera is null or the canvas is not assigned to any camera.",
  "root_cause_type": "generic",
  "root_cause_zh": "屏幕空间-叠加模式的 Canvas 需要相机来渲染射线检测，但事件相机为 null 或 Canvas 未分配给任何相机。",
  "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"
    },
    {
      "version": "Unity 6000.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "Screen Space - Camera requires a camera assignment; the error persists if no camera is set.",
      "fail_rate": 0.8,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "The null reference still occurs if the canvas is enabled at any point during the frame.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Assign the main camera to the canvas's 'Event Camera' field in the inspector or via code: canvas.worldCamera = Camera.main;",
      "success_rate": 0.98,
      "how": "Assign the main camera to the canvas's 'Event Camera' field in the inspector or via code: canvas.worldCamera = Camera.main;",
      "condition": "",
      "sources": []
    },
    {
      "action": "Change the canvas render mode to 'Screen Space - Overlay' and ensure there is at least one camera in the scene tagged as 'MainCamera'.",
      "success_rate": 0.95,
      "how": "Change the canvas render mode to 'Screen Space - Overlay' and ensure there is at least one camera in the scene tagged as 'MainCamera'.",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "Assign the main camera to the canvas's 'Event Camera' field in the inspector or via code: canvas.worldCamera = Camera.main;",
    "Change the canvas render mode to 'Screen Space - Overlay' and ensure there is at least one camera in the scene tagged as 'MainCamera'."
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://docs.unity3d.com/ScriptReference/Canvas-worldCamera.html",
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.86,
  "fix_success_rate": 0.94,
  "resolvable": "true",
  "first_seen": "2024-05-14",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}