# NullReferenceException: Physics.OverlapSphereNonAlloc returned null results array

- **ID:** `unity/physics-overlap-sphere-null`
- **Domain:** unity
- **Category:** runtime_error
- **Verification:** ai_generated
- **Fix Rate:** 95%

## Root Cause

The results array passed to OverlapSphereNonAlloc is null or not initialized before calling the method.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 2020.3.48f1 | active | — | — |
| 2021.3.30f1 | active | — | — |
| 2022.3.10f1 | active | — | — |

## Workarounds

1. **Initialize the results array before the call: `Collider[] results = new Collider[10]; int count = Physics.OverlapSphereNonAlloc(center, radius, results);`** (98% success)
   ```
   Initialize the results array before the call: `Collider[] results = new Collider[10]; int count = Physics.OverlapSphereNonAlloc(center, radius, results);`
   ```
2. **Check if results is null before passing: `if (results == null) results = new Collider[10]; int count = Physics.OverlapSphereNonAlloc(center, radius, results);`** (95% success)
   ```
   Check if results is null before passing: `if (results == null) results = new Collider[10]; int count = Physics.OverlapSphereNonAlloc(center, radius, results);`
   ```

## Dead Ends

- **** — The null check doesn't prevent the NullReferenceException from being thrown when accessing the uninitialized array in the method call itself. (95% fail)
- **** — The error is about the array being null, not its size; size is irrelevant if the array reference is null. (99% fail)
- **** — 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. (30% fail)
