General Question on using Collider2D in Unity

I need to ger OnTriggerEnter2D call from any of the two gameobjects in my setup , however I’m not sure what should be the best setup for this?

MySetup ( not sure if this is best for performance) :

Gameobject A: Components: CircleCollider2D(isTrigger Enabled), Rigidbody2D(isKinematic Enabled), TriggerHandlerScript( OnTriggerEnter2D is defined here)

Gameobject B: Components: CircleCollider2D(isTrigger Enabled)

both GameObject A & B are continuously moving.
I found in unity documentation about static colliders: StaticColliders which says Static colliders should not be moved and If you do change a static collider then this will result in extra internal recomputation by the physics engine which causes a major drop in performance.

However I’m using unity 5 which says : Moving Static Colliders will be a lot less expensive Unity5Blog

Please let me know best setup , should I use rigidbody on both gameobject or remove both of them as I don’t need physics in my game?

Collision detection is part of the physics engine. So, if you want collisions, you do need physics in your game :slight_smile: The general rule has always been:

  • If it stays still but things hit it, add a collider component.
  • If it moves around and hits other things, add a collider and a rigidbody component. (Whether you make the rigidbody kinematic or not depends on how it moves around).

The blog you mentioned states that moving static colliders will be less expensive (than it was in Unity 4), but not that it is preferable to dynamic colliders when an object is truly dynamic. So I’d stick with the rules above.

However, if you want to know what gives the best performance in your particular game setup, the only answer is to use the Profiler (and, now that that’s free in Unity 5 personal, you’ve got no excuse not to :slight_smile: