Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

ContactFilter2D does not detect a trigger even with "use triggers" enabled

Discussion in 'Physics' started by gillemp, May 11, 2019.

  1. gillemp

    gillemp

    Joined:
    Nov 23, 2015
    Posts:
    81
    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:

    Code (CSharp):
    1.         ContactFilter2D filter = new ContactFilter2D();
    2.         filter.SetLayerMask(GameManager.Instance.interactableLayers);
    3.         filter.useTriggers = true;
    4.         Collider2D[] results = new Collider2D[10];
    5.         int collidersDetected = col.OverlapCollider(filter, results);
    Thank you for your help in advance.
     
  2. gillemp

    gillemp

    Joined:
    Nov 23, 2015
    Posts:
    81
    I found out that I had disabled "Queries hit triggers" on the Physics 2D configuration section.

    Enabling it solved my problem.