I am trying to dynamically change the mesh collider at run time. After I generate the new mesh data, I set the Mesh Collider like this:
NativeArray<int3> tris = new NativeArray<int3>(mesher.triangles.Length/3, Allocator.TempJob);
for(int i = 0; i < tris.Length; i++)
{
int o = i * 3;
int3 tri = new int3((int)mesher.triangles[o], (int)mesher.triangles[o + 1], (int)mesher.triangles[o + 2]);
tris[i] = tri;
}
PhysicsCollider collider = new PhysicsCollider
{
Value = Unity.Physics.MeshCollider.Create(mesher.vertices.AsArray(), tris)
};
//if (tris.Length > 0) collider.Value = Unity.Physics.MeshCollider.Create(mesher.vertices.AsArray(), tris);
entitymanager.SetComponentData(chunkEntity.entity, collider);
entitymanager.SetComponentData(chunkEntity.entity, PhysicsMass.CreateDynamic(collider.MassProperties, 1f));
tris.Dispose();
But the game freezes at MeshCollider.Create. I have commented out lines to verify. Also, the mesher.triangles and mesher.vertices array sizes are < 1000s and that is verified. Please don’t mark this as duplicate because of that other thread with the same title