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. Join us on Thursday, June 8, for a Q&A with Unity's Content Pipeline group here on the forum, and on the Unity Discord, and discuss topics around Content Build, Import Workflows, Asset Database, and Addressables!
    Dismiss Notice

Resolved OnTriggerEnter Not Being Called

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

  1. SenpaiSumpie


    May 19, 2020

    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;
    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:
    Cinematic Components:
    Scene Change Components: SceneChangeComponents.PNG

    Any help is appreciated! Thanks.
  2. SenpaiSumpie


    May 19, 2020
    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


    Apr 5, 2016
    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


    Unity Technologies

    May 24, 2013
    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


    Apr 5, 2016
    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


    Feb 28, 2013
    Good catch!
  7. calebhc


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


    Jul 29, 2019
    Thanks. That was my case (( After upgrading the Unity to 2022 , it got broken. Reset fixed the issue.