- Home /
Physics2D.OverlapCircle dont detect triggers
I want to use this small script to find all objects with a certain tag in a certain radius. The problem is that the objects I am looking for have istrigger activated in the collider and therefore they are not detected. How can I solve this?
private void Bash()
{
Collider2D[] colls = Physics2D.OverlapCircleAll(transform.position, BashRadius);
foreach (Collider2D coll in colls)
{
if (coll.tag == "boom")
{
//Do something
}
}
}
right before if (coll.tag == "boom") put Debug.Log(coll.tag); then you will see how it is working.
Answer by MUG806 · Feb 16, 2021 at 02:15 PM
Might be worth checking if your project settings > physics 2d has "queries hit triggers" ticked
Answer by AbandonedCrypt · Feb 16, 2021 at 01:30 PM
Them having isTrigger activated or not should not matter at all, they are colliders and should be found by OverlapCircle. Your tag is likely wrong, remember that tags are case-sensitive. Also use CompareTag()
Thanks for the quick reply. I tried it with compareTag and it still doesn't work. Even if I remove the tag request, the object is not detected.
Check if it is in radius, did you do the Debug.Log() advice that @logicandchaos gave you in the comment on your answer? That should give you all the info you need. Is your tag "dog" or "Dog"?
Yes, I have tried, but nothing is displayed in the console.
Answer by Wrobb · Feb 16, 2021 at 02:27 PM
I just tried everything in a new Unity Project and everything works. No idea what the problem is but thanks for the suggestions.
Your answer
Follow this Question
Related Questions
OnCollisionEnter fires, but OnCollisionExit does not 1 Answer
Moving many 2D triggers is slow. Why? 1 Answer
How to use OverlapCollider? 1 Answer
OnTriggerExit2D Does not work 1 Answer