- Home /
Rigidbody Trigger Collider vs. Static Collider no OnTriggerEnter message
According to the Trigger message table here http://unity3d.com/support/documentation/Components/class-BoxCollider.html a Rigidbody with Trigger Collider should get an OnTriggerEnter message sent in all combinations. However, in my case this doesn't work.
I've got a non-kinetic rigidbody with a compound collider (many child objects, each with a trigger box collider). There is no collider on the parent rigidbody object. The rigidbody object passes another object in the scene, with a static box collider (non-trigger). The rigidbody object does not get any OnTriggerEnter message sent. However, I do get OnTriggerEnter message sent if I make the other object's collider a trigger as well.
Is this setup supposed to work?
Btw, I tested it some more and figured the OnTriggerEnter message gets sent to the child object's with trigger colliders, but not to the parent rigidbody object. Since the message does get sent to the parent compound rigidbody in the case of OnCollisonEnter, I would expect the same to happen with OnTriggerEnter message. Is there a way to make that happen?
Answer by jonas-echterhoff · May 25, 2010 at 12:53 PM
As you said yourself, trigger messages are sent to the object with the collider, not to the Rigidbody - this is because unlike static colliders, triggers are not (AFAIK) treated as compound colliders, so you'll get enter/exit messages for each trigger. To get the messages on the Rigidbody, you could make a simple script to iterate the parent hierarchy, until it finds a Rigidbody, and send the message to that.
Yup, that's what I did, it is just a little annoying from the programmer's point of view since you usually want to work with compound colliders on the high level, rather than adding scripts to all the children just so you could handle triggers as well. I'd love a feature added where trigger colliders are treated as compound colliders too.
can't you just do findComponentsInChildren and pass them whatever you want the trigger to... trigger?
I suppose you could put the script on the rigidbody gameObject and implement it as a "manager" which installs a simple "sensor" script on to all child trigger colliders and then uses a list to manage the common states. this would be much faster than using messages and bubbling up from the child.
Your answer
Follow this Question
Related Questions
Change size and mass on collision 1 Answer
Detect 2 non kinematic triggers? 3 Answers
Can't add Rigidbody component because collision prevents it 2 Answers
Collider2D/RigidBody2D not working 1 Answer