Search Unity

Resolved OnTriggerEnter Not Being Called

Discussion in 'Physics' started by SenpaiSumpie, Dec 22, 2020.

Thread Status:
Not open for further replies.
  1. SenpaiSumpie

    SenpaiSumpie

    Joined:
    May 19, 2020
    Posts:
    2
    Hello,

    Last night I was working on Scene Transitions when I changed from Loading Scene Name to Loading the Scene build index. After I changed this all of my IsTrigger Colliders have not been registering ANY collision. I don't think my changing of the Scene loading caused this, but I don't quite know what I did to cause this.

    I had multiple Cinematic Triggers in my Scene as well as two Scene change triggers that were working until they stopped. I have Log messages to print to see if their was a Collision, but they do not print to the console.

    I have tried multiple variations of Colliders and Rigidbodies with no luck. I even checked my Project Settings -> Physics -> Layer Collision Matrix and nothing important was unchecked.

    The Unity I was using was 2020.1.15f1, however I just upgraded to 2020.2.0f1 to see if that would fix the issue but it did not.

    I also move the player with Raycast from the Camera, so I have the triggers set to Ignore Raycast in the layer.

    Here is the code I was using + my Collider and Rigidbody set up.

    Cinematic Trigger:
    Code (CSharp):
    1. public class CinematicTrigger : MonoBehaviour
    2.     {
    3.         bool firstTime = true;
    4.         private void OnTriggerEnter(Collider other)
    5.         {
    6.             Debug.Log("Triggered");
    7.             if(firstTime && other.tag == "Player")
    8.             {
    9.                 GetComponent<PlayableDirector>().Play();
    10.                 firstTime = false;
    11.             }  
    12.         }
    13.     }
    Scene Loader:
    Code (CSharp):
    1. public class Portal : MonoBehaviour
    2.     {
    3.         [SerializeField] string sceneName;
    4.         //[SerializeField] int sceneToLoad = -1;
    5.  
    6.         private void OnTriggerEnter(Collider other)
    7.         {
    8.             Debug.Log(other.tag);
    9.             if(other.tag == "Player")
    10.             {
    11.                 Debug.Log("Load Scene");
    12.                 SceneManager.LoadScene(sceneName);
    13.             }
    14.         }
    15.     }
    Player Components:
    PlayerComponents.PNG
    Cinematic Components:
    CinematicComponents.PNG
    Scene Change Components: SceneChangeComponents.PNG

    Any help is appreciated! Thanks.
     
  2. SenpaiSumpie

    SenpaiSumpie

    Joined:
    May 19, 2020
    Posts:
    2
    After hours of scratching my head, to solve this issue I 'Reset' my Physics settings located in Edit -> Project Settings -> Physics. This fixed my issue.
     
    calebhc and erasmosoares like this.
  3. usernameHed

    usernameHed

    Joined:
    Apr 5, 2016
    Posts:
    93
    Oh my god, YES! The same code, in 2 different Unity of the same version 2020.3: one work, the other doesn't. I've verified each physic settings one to one. all the same. But by reseting them, it worked! The OnTriggerEnter finaly started to work...

    What the hell ??? :eek: :eek: :eek:


    It was a project that was initially created with 2017.XX, converted to 2018, then 2019, and finally 2020.3

    More detail about the git change might be usefull if some Unity guy come across this:

     
    Last edited: Jun 3, 2021
  4. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,456
    This thread is about 3D physics yet you're showing changes to both 2D and 3D physics setting changes (see the "DynamicsManager.asset") and assuming it's the same problem. Just start your own thread rather than assuming this is the same thing. OnTriggerEnter is 3D so which are you using?

    It's not clear what you're showing here. The 2D physics changes above show no behaviour change. m_AutoSimulation became m_SimulationMode (both are set the same). m_ReuseCollisionCallbacks defaults to off here which is default behaviour. m_AutoSyncTransforms is off too. The job-stuff was new but that's off here too.
     
  5. usernameHed

    usernameHed

    Joined:
    Apr 5, 2016
    Posts:
    93
    It was a OnTriggerEnter 3D problem. And by reseting like SenpaiSumpie it worked.

    I though it would be useful to give some feedback about the git change just in case, don't be rude about it please, I didn't wanted to create an other thread of something after 3 days of debugging and finally got it worked by just reseting the physics settings...

    And yes, I showed the 2D physics change, and if it doesn't help you, never mind.
     
    Jihaysse likes this.
  6. erasmosoares

    erasmosoares

    Joined:
    Feb 28, 2013
    Posts:
    5
    Good catch!
     
  7. calebhc

    calebhc

    Joined:
    Feb 11, 2013
    Posts:
    13
    Awesome find and thank you for sharing! Was totally lost to why triggering no longer worked after upgrading to 2022.2.0f1.
     
  8. gagasik

    gagasik

    Joined:
    Jul 29, 2019
    Posts:
    25
    Thanks. That was my case (( After upgrading the Unity to 2022 , it got broken. Reset fixed the issue.
     
  9. baeri3000

    baeri3000

    Joined:
    Mar 15, 2022
    Posts:
    1
    Woah I lost so much time debugging this xD
    But a simple reset fixed my issue as well. Luckily i found this thread here
     
  10. KillDashNine

    KillDashNine

    Joined:
    Apr 19, 2020
    Posts:
    453
    How much effort you put into solving a problem hasn't anything to do whether what you showed there was the actual cause of the problem described. Even if the practical problem's gone away, it is very important to establish what actually was the cause, because often when something suddenly "starts working", we feel release and get confirmation bias, and will incorrectly assume the cause of it. You could also call it placebo effect.

    Seems to me that the Physics component reset will reset the component to default values. If this works to solve a problem, then it seems to me that the original problem was caused by having incorrect settings in Physics, such as the "Queries Hit Triggers" flag.
     
Thread Status:
Not open for further replies.