Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

C#Jobs and Collider Mesh updates

Discussion in 'Entity Component System' started by roboman5000, Apr 25, 2022.

  1. roboman5000

    roboman5000

    Joined:
    Sep 27, 2016
    Posts:
    19
    Hi - I've got a question for those who are familiar with C# Jobs and mesh colliders.

    My goal is to get as much processing done off of the main thread as possible. However, I can't seem to get mesh colliders to update properly. I've reviewed documentation/search (here, here and here) and unfortunately haven't been able to find the correct/performant way to do this.

    At the moment, after I:
    1. Generate the MeshDataArray (job)
    2. Call Mesh.ApplyAndDisposeWritableMeshData (main thread)
    3. Physics.BakeMesh (job)
    the collision mesh (as shown in the editor) does not reflect any vertex changes. If I then:
    • disable/enable the mesh collider
    then the changes reflect - but in the profiler, it's actually re-running Mesh.Bake PhysX CollisionData... on the main thread! It doesn't seem to recognize that I've already baked the mesh. Is this an issue within Unity, or am I doing something incorrectly?

    Would love any insights you might have on this. Thanks!
     
    Last edited: Apr 26, 2022
  2. MNNoxMortem

    MNNoxMortem

    Joined:
    Sep 11, 2016
    Posts:
    723
    @roomera in 2020.1 Update https://docs.google.com/document/d/1QC7NV7JQcvibeelORJvsaTReTyszllOlxdfEsaVL2oA/edit# it is still listed as planned, but not done yet. No idea if any newer document exists. If someone has one, please link it.

     
  3. roboman5000

    roboman5000

    Joined:
    Sep 27, 2016
    Posts:
    19
    @MNNoxMortem Thank you for sharing the document. :)

    After some more digging, I stumbled on this thread, which mentions that the mesh cooking options must match in order for it to work. According to @yant,

    we will only reuse the PhysX mesh pointer stored in the Mesh instance if:
    - this MeshCollider's cookingOptions are exactly the default ones, AND
    - the MeshCollider's transform is good (*), AND
    - the Mesh instance hasn't been changed since the last time cooking was ran.


    Additionally, I also found that when you call Physics.Bakemesh, the convex parameter also has to match. Addressing all of these resolved the issue for me.
     
    MNNoxMortem likes this.