OnTriggerEnter Not Being Called

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:

public class CinematicTrigger : MonoBehaviour
    {
        bool firstTime = true;
        private void OnTriggerEnter(Collider other)
        {
            Debug.Log("Triggered");
            if(firstTime && other.tag == "Player")
            {
                GetComponent<PlayableDirector>().Play();
                firstTime = false;
            }   
        }
    }

Scene Loader:

public class Portal : MonoBehaviour
    {
        [SerializeField] string sceneName;
        //[SerializeField] int sceneToLoad = -1;

        private void OnTriggerEnter(Collider other)
        {
            Debug.Log(other.tag);
            if(other.tag == "Player")
            {
                Debug.Log("Load Scene");
                SceneManager.LoadScene(sceneName);
            } 
        }
    }

Player Components:
6650845--759772--PlayerComponents.PNG.jpg
Cinematic Components:
6650845--759769--CinematicComponents.PNG.jpg
Scene Change Components:6650845--759775--SceneChangeComponents.PNG.jpg

Any help is appreciated! Thanks.

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.

2 Likes

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 ??? :hushed: :hushed: :hushed:

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:

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.

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.

1 Like

Good catch!

Awesome find and thank you for sharing! Was totally lost to why triggering no longer worked after upgrading to 2022.2.0f1.

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

Woah I lost so much time debugging this xD
But a simple reset fixed my issue as well. Luckily i found this thread here

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.