Performance: 3D colliders
3D colliders affect the physics calculations and rendering performance by determining how objects detect collisions in a scene.
Jump into concepts and practice - no test required
foreach (var obj in objects) { if (obj.GetComponent<BoxCollider>().enabled) { // simple box collider collision check } }
foreach (var obj in objects) { if (obj.GetComponent<MeshCollider>().enabled) { // expensive mesh collider collision check } }
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| MeshCollider on many objects | N/A | N/A | High CPU physics cost | [X] Bad |
| Primitive colliders (Box, Sphere) | N/A | N/A | Low CPU physics cost | [OK] Good |
void OnCollisionEnter(Collision collision) {
Debug.Log(collision.gameObject.name);
}
What will happen when this script is attached to a GameObject with a collider and Rigidbody, and it collides with another object named "Enemy"?void OnTriggerEnter(Collider other) {
Debug.Log("Triggered by " + other.name);
}
But the message never appears when objects overlap. What is the most likely reason?