x


OnTriggerEnter not being called with multiple colliders

I have a parent GameObject with a script and a child named Colliders which has several GOs with colliders in it:

ParentGameObject
(MyScript component)
-Colliders
--Collider1
  (Collider component)
--Collider2
  (Collider component)

My test is the following: Set both colliders to non trigger: OnCollisionEnter gets called in the script. Set both colliders to trigger: OnTriggerEnter DOES NOT gets called in the script.

Any ideas why could this be happening ?

more ▼

asked May 13 '11 at 06:33 PM

Agustin Petrini gravatar image

Agustin Petrini
114 6 7 12

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

Ok, I got it. Short answer is, because Unity works like that. Long answer: OnCollision* works different than OnTrigger. OnCollision is being executed by the engine when any collider of any child collides with anything, because the parameter is aCollision which holds both colliding colliders in every contact point. This way you can actually know which collider(s) of your childs has been touched. This is different in OnTrigger*, since the parameter is aCollider (that is the OTHER collider), the only place where it is executed its on the collider´s container GO, because otherwise you wouldn´t have a way to know which collider from your child has been touched.

Hope this clears things up for somebody.

Agustin

more ▼

answered May 20 '11 at 12:33 PM

Agustin Petrini gravatar image

Agustin Petrini
114 6 7 12

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x1703
x986
x423
x411
x337

asked: May 13 '11 at 06:33 PM

Seen: 2703 times

Last Updated: May 20 '11 at 12:33 PM