# NullReferenceException: CanvasRaycaster: No camera found for canvas that is set to Screen Space - Overlay

- **ID:** `unity/ui-canvas-raycaster-null`
- **Domain:** unity
- **Category:** runtime_error
- **Verification:** ai_generated
- **Fix Rate:** 94%

## 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.

## Version Compatibility

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

## Workarounds

1. **Assign the main camera to the canvas's 'Event Camera' field in the inspector or via code: canvas.worldCamera = Camera.main;** (98% success)
   ```
   Assign the main camera to the canvas's 'Event Camera' field in the inspector or via code: canvas.worldCamera = Camera.main;
   ```
2. **Change the canvas render mode to 'Screen Space - Overlay' and ensure there is at least one camera in the scene tagged as 'MainCamera'.** (95% success)
   ```
   Change the canvas render mode to 'Screen Space - Overlay' and ensure there is at least one camera in the scene tagged as 'MainCamera'.
   ```

## Dead Ends

- **** — Screen Space - Camera requires a camera assignment; the error persists if no camera is set. (80% fail)
- **** — The null reference still occurs if the canvas is enabled at any point during the frame. (70% fail)
