Search Unity

Prebake collision mesh not working in MeshColliders created before 2019.3

Discussion in 'Physics' started by tspk91, Jan 30, 2020.

  1. tspk91

    tspk91

    Joined:
    Nov 19, 2014
    Posts:
    131
    With the update "Use Fast Midphase" flag in MeshColliders has been added. It is set as disabled in previously created components (new components start with a Mixed... value, which is the default).

    Now, the problem is MeshCollider only uses the prebaked physx representation if the cooking options are set to default. Default is every option checked. Easy right? Just go to each MeshCollider and enable them.

    Well no, if you assign every option, the "Everything" label will also be checked, resulting in a internal bitmask value of -1.

    The default cooking options bitmask of a newly created MeshCollider is 30 instead. Because for some reason, though all options are checked, the "Everything" label is not.

    So, checking everything doesn't work. Only by editing the .prefab file and setting m_CookingOptions to 30 we managed to get it to use the baked data.

    This was costing us quite a bit of loading time increase, as we generate an asteroid field at runtime. Each single instantiated asteroid was calling "Mesh.Bake Scaled Mesh PhysX CollisionData" (we checked for all the conditions that could cause it).

    An old thread which described a similar (same?) issue:
    https://forum.unity.com/threads/cas...ons-makes-mesh-require-to-be-readable.592354/
     
  2. OyvindE

    OyvindE

    Joined:
    Feb 1, 2018
    Posts:
    8
    I've been struggling with my MeshColliders after 2019.3 update aswell. Convex colliders caused massive lag spikes due to calling 'Mesh.Bake Scaled Mesh PhysX CollisionData'.
    (Made a post yesterday: https://forum.unity.com/threads/uni...cause-massive-lag-spikes-when-enabled.818913/)

    Turning off convex helped a lot, setting their cooking options to include 'Use Fast Midphase' helped a little, but its still not up to where it was before the upgrade.

    Will try your solution to see if it helps.

    Edit:
    Yep, setting their value to 30 seems to work, weird...
    Thanks!
     
    Last edited: Jan 31, 2020
    tspk91 likes this.