Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

OnTriggerEnter not working, please help!

Discussion in 'Physics' started by RadioactiveChickenGames1, Oct 18, 2020.

  1. RadioactiveChickenGames1

    RadioactiveChickenGames1

    Joined:
    Sep 29, 2020
    Posts:
    15
    I'm making a script to detect collision between a cylinder and a sphere. The cylinder is kinematic and trigger, and the sphere is nonkinematic and trigger. Unfortunately, no collision is happening. I have checked my script thoroughly at least 10 times, and I have tried pretty much every method on the Internet of fixing this. Please help! Thanks!
    P.S.: this script is attatched to the cylinder and no debug message or destruction happens when I bring the two objects together:
    Code (CSharp):
    1. void OnTriggerEnter (Collider other)
    2.     {
    3.         if (other.gameObject.CompareTag("Hazard"))
    4.         {
    5.             Debug.Log("Collision");
    6.             Destroy(other.gameObject);
    7.         }
    8.     }
     
  2. Edy

    Edy

    Joined:
    Jun 3, 2010
    Posts:
    2,428
    Configure "Project Settings > Physics > Contact Pairs Mode" to "Enable All Contact Pairs".
     
  3. RadioactiveChickenGames1

    RadioactiveChickenGames1

    Joined:
    Sep 29, 2020
    Posts:
    15
    Sorry to inform you, but that didn't work!
    P.S. I'm on unity 2019.4.11f1 for any who wonder.
     
  4. Fred-Koa

    Fred-Koa

    Joined:
    Feb 5, 2019
    Posts:
    20
    I encountered all kinds of problems with the trigger detection since 2019.3 when they changed the version of PhysX.
    They said they fixed it, but it works only randomly.
    I tried many workarounds during one year but I keep finding cases where it does not work.
    And obviously the docs for the OnTrigger... functions are outdated.
     
  5. Grenta

    Grenta

    Joined:
    Jul 31, 2018
    Posts:
    1
    I have the same problem in 2020.2
     
  6. memorylain

    memorylain

    Joined:
    Jan 25, 2021
    Posts:
    2
    Me, too, in 2020.3 ...it can´t be that such basic functions are behaving in an erratic way! Does no one have an idea how to fix this?
     
  7. SaintBob

    SaintBob

    Joined:
    Feb 21, 2014
    Posts:
    4
    Remove the trigger from the collision in the object which doesn't have the script.
    As far as I know triggers don't trigger each other, because a trigger doesn't collide per see, it checks for collisions with non-triggers. That is what I believe at least.

    Edit: clarification of reasoning.
     
  8. Fred-Koa

    Fred-Koa

    Joined:
    Feb 5, 2019
    Posts:
    20
    Colliders with triggers can interact with each others. See this doc: https://docs.unity3d.com/Manual/CollidersOverview.html
    If you don't have triggers you need to use OnCollisionEnter. If you have a trigger you need to use OnTriggerEnter. The point is that PhysX call these functions randomly.
     
    SaintBob likes this.