Search Unity

Triple performance by removing rigidbodies from trigger colliders ?

Discussion in 'Physics' started by slake_it, Mar 23, 2019.

  1. slake_it

    slake_it

    Joined:
    Aug 2, 2015
    Posts:
    74
    Hi,

    I have 3000 moving trigger sphere colliders, I have rigidbodies on them set to kinematic.
    Unity official docs recommends moving them with their rigidbody.
    However, the performance is really poor ( drops to 15 fps ), I tried removing the rigidbodies & move the triggers with their transform & the performance more than tripled.

    here are the numbers:
    ( I know fps is not an accurate measure, but the difference is very clear in performance & I simply want to compare different systems - not get absolute numbers )

    1. moving triggers / rigidbody game objects using transform.position gives me 15 fps
    2. using rigidbody.position or .movePosition gives 15 fps, it goes up to 30fps when disabling Physics.autoSyncTransforms
    3. removing the rigidbodies ( keeping only trigger colliders ) & using transform.position generates 60 fps

    4. using Update is much faster than Fixed Update ( whether using transform.position or rigidbody.position or .MovePosition)


    @MelvMay
    1- I need to know if moving trigger colliders without a rigidbody can cause bugs, because performance wise, it is clearly much much faster.
    2- is there any reason why removing rigidbodies enhances performance ? ( am doing anything wrong ? )

    Thanks ;)
     
    Last edited: Mar 23, 2019
  2. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    1,966
    I already saw your other post here and answered for 2D physics because I don't work on the 3D physics team. You need to speak to @yant
     
    Last edited: Mar 24, 2019
  3. slake_it

    slake_it

    Joined:
    Aug 2, 2015
    Posts:
    74
    Hi @MelvMay
    Thanks for the help, I thought you worked the 3D physics.
     
  4. slake_it

    slake_it

    Joined:
    Aug 2, 2015
    Posts:
    74
    Hi @yant , What do you think about this performance behavior ?
    Thanks
     
  5. yant

    yant

    Unity Technologies

    Joined:
    Jul 24, 2013
    Posts:
    305
    So to clarify -- we made the static Colliders use the same pruning structure as the dynamic ones around Unity 5.0, that came in with the PhysX 3.3 upgrade back then. Before that, it was super costly to move the static Colliders without Rigidbodies, and the knowledge about that had been spread out for ages. Unfortunately, when the PhysX change went in, not all of the places were updated so you can still encounter recommendations to use Rigidbody when it's no longer actually needed so.

    Now, as to the downsides -- yes there are. Static colliders aren't exactly expected to be moved around frequently. There is a bunch of optimisation involved. Some objects won't be awoken up when the platform they rested on top of has been moved away. Vehicles have a lot of that stuff going for perf reasons.
     
    slake_it likes this.
  6. slake_it

    slake_it

    Joined:
    Aug 2, 2015
    Posts:
    74
    @yant Thanks a lot for helping,
    Just to clarify, I'm not using static colliders ( just moving trigger colliders without rigidbodies on them ).
     
  7. yant

    yant

    Unity Technologies

    Joined:
    Jul 24, 2013
    Posts:
    305
    A static collider is any Collider that doesn't have Rigidbody component attached to any gameobject up the hierarchy. It's indeed supposed to be stationary, not moved., however the cost of that move has been reduced dramatically over the years like I posted above. Thanks for your interest in physics.
     
    slake_it likes this.
  8. slake_it

    slake_it

    Joined:
    Aug 2, 2015
    Posts:
    74
    Ah I see, I thought it should be marked as static
    Thanks again for the help