1
\$\begingroup\$

I'm Using Unity 2018.3.11f1 and I'm going crazy trying to understand why the "use triggers" variable of the ContactFilter2D is not having any effect and I'm always detecting only the non-trigger colliders.

The problem is just as simple as that: If I use the OverlapCollider trying to detect a collider that is not a trigger it works perfect. However, if that collider is set as trigger the "OverlapCollider" does not detect it even if I set the variable "useTriggers" of the used filter is set to true (and obviously in false the same behavious appears)

Does anyone have any clue about why it happens?

This is the code:

    ContactFilter2D filter = new ContactFilter2D();
    filter.SetLayerMask(GameManager.Instance.interactableLayers);
    filter.useTriggers = true;
    Collider2D[] results = new Collider2D[10];
    int collidersDetected = col.OverlapCollider(filter, results);

Thank you for your help in advance.

\$\endgroup\$
1
\$\begingroup\$

I found out that I had disabled "Queries hit triggers" on the Physics 2D configuration section.

Enabling it solved my problem.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.