Search Unity

Moving kinematic rigidbody with child rigidcodies has high performance impact

Discussion in 'Physics' started by Peaj, Apr 30, 2018.

  1. Peaj

    Peaj

    Joined:
    Jul 11, 2012
    Posts:
    2
    Hi,

    I have a physics related performance problem and I wonder if anybody has an idea how to improve it.

    I have a kinematic rigidbody (boat) which has a lot of non-kinematic rigidbodies (items) in it.
    The boat is being moved by code in the update method.

    Even though moving the boat will (or should) never cause any of those items to collide with anything the moving items use up a lot of performance.

    Any clues how to reduce this performance overhead is much appriciated.
     
  2. Edy

    Edy

    Joined:
    Jun 3, 2010
    Posts:
    2,508
    The kinematic boat should be moved using Rigidbody.MoveRotation and Rigidbody.MovePosition from FixedUpdate.

    Note that the non-kinematic objects will be colliding with the boat anyways, regardless of the parenthood relationship. A Rigidbody component just overrides its GameObject's Transform based on the physics interactions.
     
  3. BrandyStarbrite

    BrandyStarbrite

    Joined:
    Aug 4, 2013
    Posts:
    2,076
    How many non-kinematic rigidbodies (items), do you have in that boat?
     
  4. Peaj

    Peaj

    Joined:
    Jul 11, 2012
    Posts:
    2
    Thanks for your replies. I tried moving it via MovePosition and MoveRotation but the performance gets even worse. Before it went from 60 down to around 42 FPS and now it goes down to 37 FPS.
    The number of items depends on how many the player buys. Currently its limited to 3 per item which results in around 40 items max. But usually its just around 15 items in the boat
     
  5. Deeeds

    Deeeds

    Joined:
    Mar 15, 2018
    Posts:
    739
    Can you approximate the mass of the objects, deactivate them as physics bodies, nest them to the boat and make a simple, single physics body that replaces their mass?
     
  6. BrandyStarbrite

    BrandyStarbrite

    Joined:
    Aug 4, 2013
    Posts:
    2,076
    Interesting.
    What happens, if you only have a few objects, like 5 or 10 items, in the boat?
    Is the performance better?