I have a simple test situation boiled down from a problem I'm having.
Two game objects, Cube1 and Cube2. Each of Cube1 and Cube2 are built from the model following.
Each has a child... CubeChild1 is a child of Cube1, and CubeChild2 is a child of Cube2.
Cube1 and Cube2 have rigidbodies, each with gravity turned off.
CubeChild1 and CubeChild2 each have a box collider that is in trigger mode. There are no other colliders.
Cube1, Cube2, CubeChild1, and CubeChild2 each have a common script "SimpleOnEnterTrigger" as below:
` using UnityEngine; using System.Collections; public class SimpleOnEnterTrigger : MonoBehaviour { void OnTriggerEnter(Collider collider) { Debug.Log(gameObject.name + " . OnTriggerEnter (" + collider.gameObject.name + ")"); } } `
To reiterate the point, Cube1 and Cube2 (including children) are identical except for naming, and the naming is just so the debug outputs distinctly.
On running the scene, I drag Cube1 cube on top of Cube2. I get the following output:
CubeChild1 . OnTriggerEnter (CubeChild2) Cube2 . OnTriggerEnter (CubeChild1)
It is strange enough already -- there is an asymmetry. CubeChild1 is getting the collision message in the one direction, but CubeChild2 is not! Instead, the message ends at the parent, Cube2.
When I run the scene again, but move Cube2 on top of Cube1, I get exactly the same debug output. This is consistent in the sense that it should not matter which Cube is being moved.
I would have expected that the results would be symmetric. Either the messages would both end up going to the nearest parent gameobject containing a rigidbody, or (and this seems to make more sense) the messages would go to the gameobject containing the trigger.
Using kinematic rigidbodies doesn't seem to make any difference.
Why the asymmetry?
Its not a matter of filtering the colliders in OnTriggerEnter, which I knew I'd have to do. All the expected messages get sent, but just to unexpected places.
This comes up in a practical situation. I have a vehicle with a rigidbody (and, full disclosure, actual non-trigger colliders), which also needs to carry around some trigger volumes with it. It will interact with other such vehicles, and I need to identify when these trigger volumes interact with the partners. This is the boiled-down version to illustrate.