OnTriggerEnter only works if gameObject is moving

Hi,

I have a question regarding the onTriggerEnter function. My scene has the following set up:

I have one gameObject with a rigidbody component and is Kinematic set to true. This object can be controlled by the player and should avoid upcoming obstacles, without beeing affected by the physics system.

The obstacles have a box collider and isTrigger set true.

the player object has the following script running:

function OnTriggerEnter(myTrigger : Collider){

Debug.Log(myTrigger.gameObject.name)}

My problem is that the onTriggerEnter function is only called when I move the player object, while it hits the trigger. If it is standing still while the trigger hits it, the function is not called. Is there a failure with the script or the set up? Because I need to activate the trigger, even if the player object is not moving.

Thanks in advance

Incase others might come across this, I was having an issue where a collider2d that I toggle activate wasn’t triggering OnTriggerEnter2D until I moved. The solution for me was that I had to set my RigidBody2D sleeping mode to Never Sleep.

I had exactly the same problem. It took a bit of figuring out but the documentation on BoxCollider states that:

“If you are moving an object through its Transform component but you want to receive Collision/Trigger messages, you must attach a Rigidbody to the object that is moving.”

I ended up having to add a Rigid body to both of my objects for this to work consistently, because they were both moving objects.

Just looked through the documentation. Maybe you can find your answer here:

BoxCollider and triggers

I have the same Problem and as I see, this is one of the first threads to pop up in google.

To fix the bug in my case a added the rigidbody to the moving object instead of the player. Now both have rigidbodys and behave as intended.

Hope this helps

I still got the same symptom although my gameobjects already had Rigidbody, as other answers mentioned.

Then, I found that even having Rigidbody, onTriggerEnter is still not called if the both gameobjects’ rigidbodys do not have “Use Gravity” checked.

Checking “Use Gravity” of Rigidbody on either gameobject makes onTriggerEnter called without the gameobjects moving.

It’s been a while since the question is raised, so that I’m not sure it was the case back then, but at least, it works this way as of Unity 2018.2.18f1.

btw, this is also the same for OnCollisionEnter.