Should I put a rigidbody on colliders moved by script ?


I’m wondering if a rigidbody is required or not when moving a collider by script. This collider can collide with dynamic objects (these objects have a non-kinematic rigidbody), and no script callback (OnCollisionXXX) is required.

I tried both (without rigidbody attached and with a kinematic rigidbody attached), and the result look the same : All the dynamic objects collide normally with this “moving wall”.

I’ve heard that it’s best practice performance-wise for the physics engine to have a kinematic rigidbody on moving colliders. Is this true ? or is it only true if I want collision callback ?

Thanks a lot!

If using 3D physics there’s no need to add a Rigidbody to moving colliders. There will be no performance gain, maybe the opposite (as there’s an additional Rigidbody the physics engine has to handle).

OnCollisionXXX callbacks are invoked as long as one of the involved colliders has a Rigidbody attached.

If using 2D physics, as far as I know it’s the opposite: add a rigidbody to your moving colliders to avoid performance penalties.

Ok I’m confused :smiley:

For example, this tutorial says the opposite :

The thing is that this advice seems to be from Unity 4.x. It’s been a while since.
Did the physics engine changed in a way that this is not required anymore ?