Search Unity

Moving stuff without Rigidbody better for performance?

Discussion in 'Scripting' started by Shack_Man, Mar 11, 2020.

  1. Shack_Man

    Shack_Man

    Joined:
    Jun 7, 2017
    Posts:
    372
    I know the standard practice of using rigidbodies when moving colliders so the physics system knows they are supposed to move. I'm pretty sure though that I read somewhere that this is no longer the case, but I can't find where.

    I've been playing around with the profiler and this confirms it. I'm moving units with a sphere collider on a terrain with a terrain collider. They are barely overlapping and moving every frame. I've tried different methods of moving them and using good ol' transform.position = ... beats everything that involves a rigidbody.

    Does anyone know if this was mentioned somewhere? Or maybe it's just that in my very specific scenario this is the case and the "add a rigidbody when moving a collider" rule should still apply?

    Thanks!
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,674
    What are you trying to do?

    1. you use Rigidbodies because you WANT the extra computation and functionality of the physics system.

    2. you also use Rigidbodies for things you need physics collisions to happen with, but want to move them yourself (isKinematic)

    3. for anything else, move it as you like, you'll save a lot of CPU time, but you have to do your own collision and overlap detection, if you need it
     
  3. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    I quoted the manual which still says not to move static colliders the other day and was called out for the information being out of date.

    As far as performance though, the physics system does a lot of work now in its own separate threads. Saving CPU on the physics threads is usually of less value than saving CPU on the main thread. Just something to consider as you're weighing your options here.
     
  4. Shack_Man

    Shack_Man

    Joined:
    Jun 7, 2017
    Posts:
    372
    Thanks guys! In my case I am moving objects that have colliders only so that other objects can shoot raycasts and detect them. This is far from happening every frame though and I don't need colliders to check collisions with each other.