Very confused... Physics.OverlapSphere working, but not NonAlloc version?
Suddenly, all my NonAlloc versions of Physics.Overlap just stopped returning any colliders. Thought I was going crazy, until I put the identical regular versions above them. The regular versions are functioning just fine... the _hitColliders array it's outputting to also becomes null.
Any ideas? A physics bug?
Answer by alpineboarder · Dec 13, 2020 at 05:34 PM
For some odd reason my Collider array was becoming null, even though it was initialized as Collider[] _hitColliders = new Collider[25]; in its declaration.
By adding _hitColliders = new Collider[25]; again in the code, it started functioning properly again. Still confused, but at least it's working!
It's possible that if you initialized it in Start(), that a FixedUpdate() or Update() frame might happen before it gets initialized, or it might get called from some other script before Start() was called.
Answer by shieldgenerator7 · Dec 18, 2020 at 09:33 PM
One thing to check is that the size or your array is large enough. If enough elements are found and the array is small enough, certain objects you're looking for might not be in the array. With 25 elements you should be safe, but it is still a possibility.