Why is OverlapPointAll not getting a collider sometimes?,
I'm needing to get the colliders at the mouse position, for some reason its very incontinent, without moving my mouse it occasionally doesn't get anything, I don't see why it would work sometimes but not other times when nothing has changed. I've tried alternatives to overlappointall but they're all having the same problem. OnMouseOver works perfectly tho, but obviously I can't use that to get all the colliders at a location.
Code:
void GrabDraggableUI()
{
Collider2D[] cols = Physics2D.OverlapPointAll(Camera.main.ScreenToWorldPoint(Input.mousePosition), LayerMask.GetMask("UI"));
if (cols.Length > 0)
{
int topHit = 0;
int preValue = 0;
if (cols[0].transform.GetComponent<SpriteRenderer>())
{
preValue = cols[0].transform.GetComponent<SpriteRenderer>().sortingOrder;
}
else if (cols[0].transform.GetComponent<SpriteLink>())
{
preValue = cols[0].transform.GetComponent<SpriteLink>().spriteRenderer.sortingOrder;
}
for (int i = 0; i < cols.Length; i++)
{
int tempValue = 0;
if (cols[i].transform.GetComponent<SpriteRenderer>())
{
tempValue = cols[i].transform.GetComponent<SpriteRenderer>().sortingOrder;
}
else if (cols[i].transform.GetComponent<SpriteLink>())
{
tempValue = cols[i].transform.GetComponent<SpriteLink>().spriteRenderer.sortingOrder;
}
if (tempValue > preValue)
{
preValue = tempValue;
topHit = i;
}
}
if (cols[topHit].transform.GetComponent<Drag>())
{
cols[topHit].transform.GetComponent<Drag>().grabbed = true;
draggingUI = true;
}
}
}
,
Your answer
![](https://koobas.hobune.stream/wayback/20220613045639im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Check if two spheres are overlapping one another? 1 Answer
What is the best way to do a 2D Ground Check? 0 Answers
Feild of view only wokring in specific areas of the scene 0 Answers
How to cast a Ray using local pivot of an object? 1 Answer
Can you raycast to detect a point on the other side of a cube 0 Answers