- Home /
 
Is Overlap Circle Supposed to return inactive colliders?
So I am using OverlapCircleNonAlloc to do damage to some other game objects. The OverlapCircle gets the colliders of the objects in the circle correctly the first time. I then disable the object because I eventually want to reset the objects. But when I do the overlap circle again it finds the disabled object.
         Physics2D.OverlapCircleNonAlloc(
                     ball.Position, 
                     triggerRadius,
                     results, layers.brickLayer
         );
         foreach (Collider2D col in results)
         {
             if (col != null && layers.brickLayer.LayerContains(col.gameObject.layer))
             {
                 col.gameObject.GetComponent<Brick>().Damage(
                     ball.Position, 
                     DamageType.Lightning
                 );
             }
         }
 
               Is this a bug? Or is OverlapCircle intended to find objects that are not enabled.
Answer by Snowdrama · Jul 29, 2020 at 10:44 AM
Okay Turns out it was not directly related to the circle collider itself but the fact that I was using the "NonAlloc" version and it only overwrites the existing entries, I was assuming it was setting all the entries that it doesn't use to null. So if it got only 1 result this time but 5 results last time, there wouldd be 5 results in the array since I didn't clear/null the array entries first.
Solution:
Either do results = new Collider2D[20];
or use OverlapCircle instead of OverlapCircleNonAlloc
Your answer
 
             Follow this Question
Related Questions
Multiple Collider of Platform Effector overlap Problem 1 Answer
Updated Unity, 2D Colliders not working. OnTriggerEnter2D not working 0 Answers
Checking for Colliders with Physics2D.OverlapBoxAll Won't Work? 0 Answers
Bullets go through collider even with continuous collision detection! 0 Answers
Workarounds for Higher Control When Using Physics2D? 0 Answers