Performance: OnCollisionEnter2D and OnTriggerEnter2D
MEDIUM IMPACT
This affects the physics simulation and event handling performance during gameplay, impacting frame rate and input responsiveness.
void OnTriggerEnter2D(Collider2D other) {
// Simple trigger used for overlap detection
Debug.Log("Trigger entered by " + other.gameObject.name);
}void OnCollisionEnter2D(Collision2D collision) {
// Heavy physics collision used just to detect overlap
Debug.Log("Collision detected with " + collision.gameObject.name);
}| Pattern | Physics Cost | CPU Usage | Frame Impact | Verdict |
|---|---|---|---|---|
| OnCollisionEnter2D for overlap detection | High (full collision resolution) | High | Can cause frame drops | [X] Bad |
| OnTriggerEnter2D for overlap detection | Low (simple overlap check) | Low | Smooth frame rate | [OK] Good |