Search Unity

Mesh.Bake PhysX CollisionData profiler item

Discussion in 'Physics' started by Prophet6989, Mar 5, 2015.

  1. Prophet6989

    Prophet6989

    Joined:
    Jul 8, 2012
    Posts:
    37
    Hello. I've making procedural trigger generation and get huge spikes of "Mesh.Bake PhysX CollisionData", which takes up to 85% of frame time. All objects in heararhy has scale (1; 1; 1) and not marked as static. Here is my code
    Code (CSharp):
    1. _mesh.Clear();
    2.  
    3. // generating verts/tris arrays
    4.  
    5. _mesh.vertices = _verts;
    6. _mesh.triangles = _tris;
    7. _mesh.Optimize();
    8. _meshCollider.sharedMesh = null;
    9. _meshCollider.sharedMesh = _mesh;
    If I comment line
    Code (CSharp):
    1. _meshCollider.sharedMesh = null;
    spikes go away, but MeshCollider is not updating. Does anyone know possible solution?
     
  2. Nanako

    Nanako

    Joined:
    Sep 24, 2014
    Posts:
    1,047
    what do you mean procedural trigger generation?

    it sounds like the spike is caused by updating a whole lot of colliders. Needing to set it to null before changing it sounds like a bug to me. But updating a lot of colliders causing a lag spike sounds like a very logical thing. It would depend on your circumstances though.

    I think you should report that bug, and i would try using a coroutine with a stopwatch indstrumenting it, in order to space these calculations out over several frames and prevent performance hits.
     
  3. Brainswitch

    Brainswitch

    Joined:
    Apr 24, 2013
    Posts:
    270
    The spike is because you are updating mesh colliders, which can be performance heavy if you do it on complex (in regards to physics meshes become complex much quicker than in regaards to graphics) meshes. Try to space out the updates over several frames and if possible reduce or split your meshes.
     
  4. Nanako

    Nanako

    Joined:
    Sep 24, 2014
    Posts:
    1,047
    if you need to use mesh colliders its a good idea to create a much lower resolution, simpler version of your mesh, to be the collider