Search Unity

Ways to avoid PhysX mesh baking calculations?

Discussion in 'Editor & General Support' started by Damocles, Jun 22, 2013.

  1. Damocles

    Damocles

    Joined:
    Jul 21, 2012
    Posts:
    46
    I have an issue where in my game I want to spawn a bunch of debris items when an object is destroyed. This all works fine, and I'm using pooling/caching etc, but I still get a stutter when I spawn (activate pooled objects) the debris.

    The profile is showing the majority of the time is eaten up with "Bake Scaled Mesh Physx Collision Data", which after some digging seems it's PhysX having to recalculate and bake collision data for new objects. This is happening because each of the debris items are at random scales, so PhysX needs to recalc the newly scaled mesh collider for every debris item.

    It's looking like my only way around this is to replace the convex mesh colliders of the debris items with primitive colliders. I'm hoping someone here will stop me and say "hey, wait a minute! you can do such and such!" which will let me keep the convex mesh colliders without the stuttering. Any ideas?
     
  2. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Add a rigidbody if you haven't done so... and try disabling the component for rendering / physics rather than hiding, see if that helps.

    edit: ah i see mesh colliders are used. Use box colliders or sphere colliders for debris.
     
  3. Damocles

    Damocles

    Joined:
    Jul 21, 2012
    Posts:
    46
    Yeah the issue comes when I change the scale of the debris (for random variation) and PhysX needs to re-bake the colliders.

    I guess I have two choices:

    Make a pool of pre-random sized debris, which I would rather not do because I want the object being destroyed to be able to determine the min/max scale of the debris,

    Use primitives.

    I guess option two is my best bet, unless anyone else has a brilliant idea..........anyone.......at all?
     
  4. Map-Builder

    Map-Builder

    Joined:
    Aug 29, 2012
    Posts:
    11
    I know that's an old subject, but that could help a bunch of people :

    The problem doesn't come form making them "pop".
    Scaling a meshCollider child of a rigidbody (not sure about rigidbody itself but probably too) makes physics recalculate. Scale them before and instantiate randomly different scales for those objects.