Source:
Particularly:
Note: Both GameObjects must contain a Collider component. One must have Collider.isTrigger enabled, and contain a Rigidbody. If both GameObjects have Collider.isTrigger enabled, no collision happens. The same applies when both GameObjects do not have a Rigidbody component.
Observation 1:
Projectile: contains mesh renderer, mesh filter and sphere collider (isTrigger = false)
Cube: contains mesh renderer, mesh filter, RigidBody and box collider (isTrigger = true)
Projectile contains a MonoBehavior with OnTriggerEnter printing collision confirmation.
Projectile is instantiated via script and moved toward Cube at runtime.
The OnTriggerEnter event works as expected when these 2 objects collide.
Result: This works inline with the documentation provided.
Observation 2:
Sphere2: contains mesh renderer, mesh filter and sphere collider (isTrigger = false)
Cube: contains mesh renderer, mesh filter, RigidBody and box collider (isTrigger = true)
(identical setup of object components between these observations)
Sphere2 contains a MonoBehavior with OnTriggerEnter printing collision confirmation.
Sphere2 is childed to another gameobject and moves with it during runtime.
The OnTriggerEnter event does not detect the collision when 2 object colliders intersect.
Result: This does not work inline with the documentation provided.
Workaround for Observation 2:
If the sphere collider on Sphere2 is marked isTrigger = true, the collision is detected.
However ,this means that both the Sphere2 and the Cube objects have their collider marked isTrigger = true.
This directly contradicts the documentation.
Am I missing something?
1 Like
I did more tests and will mention the ones below that contradict the documentation or behave inconsistent with expectations.
It’s worth saying that my goal here is to simply understand how these values impact gameplay and what standard I should use to determine whether an object needs a RB, a collider, or both, and what values should be set to achieve results. I’m getting a mixed bag of outcomes.
For all tests, the default state of objects is (unless noted per test):
Cube: rigidbody, box collider with trigger = false (stationary gameobject)
Sphere2: sphere collider with trigger = true (this is parented to an object that moves at runtime - no rigidbodies)
Projectile: sphere collider with trigger = true (this is an object instantiated on command at runtime - no rigidbodies)
Inconsistency 1: Removing the Rigidbody from the Cube
Sphere2 and Cube still detect collisions on both objects (both objects have an identical monobehavior that fires OnTriggerEnter), despite no rigidbody interaction.
Projectile and cube do not detect collisions with each other.
Why would these 2 behave differently?
Inconsistency 2: Cube isTrigger doesn’t appear to matter.
Other colliders will detect the cube (and vice versa) whether isTrigger is true or false on the cube. This seems like a direct contradiction to the documentation.
Inconsistency 3: Sphere2 detects everything.
Sphere2 collider detects every other collider, including those with no rigidbody component attached to the gameobject. This seems like a good thing, but directly contradicts the documentation.
I put a simple monobehavior on all the objects tested to confirm if the source of the colision detection was specific to a particular object in the itneraction, and found that it is not.
private void OnTriggerEnter(Collider other)
{
print($"{this.name}: {other.gameObject.name}");
}
1 Like
Just to make it clear, the documentation for OnTriggerEnter has the following note (the doc link and note are in the OP above):
Note: Both GameObjects must contain a Collider component. One must have Collider.isTrigger enabled, and contain a Rigidbody. If both GameObjects have Collider.isTrigger enabled, no collision happens. The same applies when both GameObjects do not have a Rigidbody component.
The observations I posted above suggest that out of these 4 sentences, only the 1st one appears accurate. Sentences 2, 3, and 4 are wrong.
1 Like