Search Unity

  1. Improved Prefab workflow (includes Nested Prefabs!), 2D isometric Tilemap and more! Get the 2018.3 Beta now.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. Let us know a bit about your interests, and if you'd like to become more directly involved. Take our survey!
    Dismiss Notice
  4. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice
  5. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

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:
    1,212
    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:
    986
    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:
    986
    Interesting.
    What happens, if you only have a few objects, like 5 or 10 items, in the boat?
    Is the performance better?