Strange Behavior of Mesh Collider for Dynamic Mesh

Hi,

I am getting crazy with a mesh collider that does not want to work.

I believe, I am missing an update function call but I don't see where.

What makes me suspect this, and, what is really strange is that if I change the physical material in the inspector at run time then the mesh collider detects the collisions correctly.

Basically, the mesh is created by a script during the update function of the component.

The script is very similar to the procedural mesh samples provided by unity in its sample collection.

  1. I tried different methods of initialization of the mesh collider and of the physical material but it seems that does not change anything. The physical material loaded is "wood".
  2. I am using sharedMesh , and sharedMaterial all along the way. I also did try to reaffect them as necessary...
  3. The loaded material is present in the inspector at runtime.
  4. I tried attaching a rigidbody in kinematic mode it did not change the result.
  5. I tried calling various update functions such as RecalculateBounds() or WakeUp(), no effect...

Does anyone had similar experience ? or have one idea of the the reason that would explain why chaging the material in inspector starts make working the mesh collider, and what kind of call I may be missing to make work the mesh collider.

Thanks for any help...

Bertrand

Well, I believe I have finally found out what was going on... I had left some degenerated triangles(all nodes to the same vertex) in my mesh, these one were not visible and had not effects, except that removing them, re-enable the collision with the mesh...

It is likely that these degenerated triangles in the mesh were generating a "division by zero" exception in the meshcollider code... and that for this reason the mesh collider code was returning without reporting collisions.

If this is the correct explanation, I believe a warning should be issued to inform the developper of that collisions have not been handled due to some invalid triangle in the mesh.

I did like this

MeshCollider meshCollider = GameObject.Find("YOUR TARGET GAME OBJECT").GetComponent<MeshCollider>();
meshCollider.convex = true;