- Home /
[Closed]Physics2D.OverlapPoint gets which collider?
Hi ,
EDIT: It was an issue regarding layermasks.
I am using Physics2D.OverlapPoint with Layermask to detect whether the touch position on the screen has a collider at that point.
BUT, lets say i have more than 1 collider2D in the same place, then what will Physics2D.OverlapPoint return?
Since we cannot give z depth for 2D colliders, how to sort the collider2D's so that i will know which collider2D is returned and it will not be ambiguous.
The main problem is, Im not getting the collider2d which i expect to get since the object's Z is lowest and yet the collider2D i get is of the one which Z position is more than that object! That is Weird.
Answer by Armand · Jul 09, 2014 at 03:03 PM
Hmm, could be a bug, the 2D features are quite new after all. OverlapPoint should always return the object with the smallest z component, in case there are more than one. Anyway, you could just use Physics2D.OverlapPointAll, the first element in the returned array should be the one with the smallest z component.
Actually, the root cause of the issue was layermasks! That was all messed up after combining three layers. Later corrected that issue and it gets the proper collider. But anyhow thanks a lot :)
Your answer
![](https://koobas.hobune.stream/wayback/20220613153617im_/https://answers.unity.com/themes/thub/images/avi.jpg)