Updating a mesh collider

I am building two meshes procedurally, one for the mesh renderer and one for the collider. For some reason the collider does not work unless the same mesh is set to the mesh filter as well. Is there something I need to do to the collider to make it work?

        // update the chunk mesh
        chunk.node.f.mesh.Clear();
        chunk.node.f.mesh.SetVertices(mesh.verts.ToNativeArray<Vector3>(Allocator.Temp));
        chunk.node.f.mesh.SetTriangles(mr.mesh_faces.ToArray(), 0);
        chunk.node.f.mesh.SetUVs(0, mesh.uvs.ToNativeArray<Vector3>(Allocator.Temp));
        chunk.node.f.mesh.RecalculateNormals();
        if (chunk.node.f.mesh.vertexCount > 0) { 
            chunk.node.c.sharedMesh.Clear();
            chunk.node.c.sharedMesh.SetVertices(collider.verts.ToNativeArray<Vector3>(Allocator.Temp));
            chunk.node.c.sharedMesh.SetTriangles(mr.collider_faces.ToArray(), 0);
            chunk.node.c.sharedMesh.SetUVs(0, collider.uvs.ToNativeArray<Vector3>(Allocator.Temp));
            chunk.node.c.sharedMesh.RecalculateNormals();
            chunk.node.c.sharedMesh.RecalculateBounds();
        }

The above is setting the collider sharedMesh data manually (but it’s the same exact data as the meshfilter) but the collider doesn’t work, nothing collides with it.

But if I set the collider to the meshfilter data like so.

chunk.node.c.sharedMesh = chunk.node.f.mesh;

It works fine. Do mesh colliders need the same data as the meshfilter to function?

EDIT:

When I create a new mesh and then assign it that way…

Mesh m = new Mesh();
m.SetVertices(collider.verts.ToNativeArray<Vector3>(Allocator.Temp));
m.SetTriangles(mr.collider_faces.ToArray(), 0);
m.RecalculateNormals();
chunk.node.c.sharedMesh = m;

It works as well. I guess you cannot change the collider mesh data with SetVertices etc? Feels like a bug. :thinking:

If I have to do it this way then it will create more garbage no?