I have a "car" object with 2 colliders attached, a base and a top collider. Then I have a script attached to my car. I'm using OnTriggerEnter event to detect collisions with an invisible "Checkpoint". The problem is that OnTriggerEnter is called twice, I suppose because it is called either from the base collider and top collider. I want to check my object collider's name. OnTriggerEnter expose me with "other" collider; however, how can I test my collider's name?

  • \$\begingroup\$ I have been searching for the answer to this exact question. This should be extremely basic functionality of the OnTrigger event... \$\endgroup\$ – Shadoninja Dec 30 '17 at 17:46

You don't need to check the current object tag, since the OnCollisionEvent would only fire on the object you attached your monobehaviour script to.

Either your GameObject is bouncing and is registering two collision enter events in quick succession -- or it is colliding with at least 2 other colliders.

Tag your collider types so you can easily check to see what you are colliding with. Then you can add a debug statement in your OnCollisionEnter to see what is going on:

Debug.Log("Collided With: " + collider.gameObject.tag);
| improve this answer | |
  • \$\begingroup\$ I need to check, because my script is 'attached' to main game object, but the two collider are child of an empty child gameobject .. About collider.gameObject.tag Unity tell me it is obsolete and won't compile :( \$\endgroup\$ – stighy Jun 4 '16 at 12:19
  • \$\begingroup\$ As the asker describes, the object has a sub object that has a second collider. The second collider is firing the second OnCollisionEvent. I have just confirmed that this setup will fire two events; not just one. \$\endgroup\$ – Gnemlock Dec 4 '16 at 2:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.