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

Multithreading Mesh.Bake.PhysX.CollisionData

Discussion in '2019.3 Beta' started by crysicle, Aug 15, 2019.

  1. crysicle

    crysicle

    Joined:
    Oct 24, 2018
    Posts:
    95
    Hello, i've come into a bottleneck problem with mesh deformation. For my project i'm trying to deform meshes for terrain collision every frame. The range of vertices necessary to be synced by physics ranges from 300 to 10k. The lag comes from using the updated meshes inside a MeshCollider, which causes physics to rebake the collision data. The performance hit on my i7-5820k is about 1ms for every 1k vertices manipulated with an odd spike which doubles the lag amount. Making the meshes bigger or smaller has no noticable effect. The lag mostly correlates to the amount of vertices changed in total. Making the maximum amount of vertices i can manipulate each frame without really high performance costs of about 2-3k.

    While the lag isn't much if i keep the maximum vertice count low, i'd prefer not to limit myself gameplay wise to such a degree. It would mean i would have problems using any fast projectiles in my game, as well as, greatly reduce the amount of objects i could have in a scene which should collide with the terrain.

    After digging the forums a bit i found that "Mesh.Bake.PhysX.CollisionData" running on a main thread seems to be an issue running back many years when it comes to procedural mesh generation. Has there been any changes regarding this with the new versions of Unity? New method indroduced with 2019.3 "Physics.BakeMesh()" does not have any effect on the actual PhysX initialization and neither do the various MeshCollider baking options. The new Mesh API changes in this link doesn't talk about physics regarding meshes at all. I hope i didn't hit a complete dead end here.

    Hopefully someone can shine some light on this. Thanks.
     
  2. richardkettlewell

    richardkettlewell

    Unity Technologies

    Joined:
    Sep 9, 2015
    Posts:
    2,239
    Hey, I've had a quick look at what code runs inside this profile marker, and it appears to be almost entirely code inside the PhysX library.

    Unfortunately I don't envisage that this is something we will be able to optimise in the near future - we would most likely require input from NVidia as it is their library.
     
    Peter77 and crysicle like this.
  3. crysicle

    crysicle

    Joined:
    Oct 24, 2018
    Posts:
    95
    I see, thanks for the reply.
     
  4. TerraUnity

    TerraUnity

    Joined:
    Aug 3, 2012
    Posts:
    1,186
    Any updates on this now since new mesh scripting API is updating frequently? No replies on this!
     
  5. Atangames

    Atangames

    Joined:
    Sep 16, 2020
    Posts:
    16
    TerraUnity likes this.