Can't change verts on mesh after assigning to meshfilter.

177835-screenshot-2021-03-19-165154.jpg

I’m editing the verts in my hex meshes to deform them. The hexes are working fine but I’m unable to change the water hexes and I’m not sure why. The land hexes are instantiated prefabs with the mesh already assigned. The water hexes I use this to get the mesh.

            Transform obj = waterHexMeshes.transform.Find(meshName);
            if (obj) {
                clientHex.meshFilter.mesh = obj.GetComponent<MeshFilter>().sharedMesh;
            }

This is used to deform the mesh. This runs on all the hexes both water and land.

    public void DeformMesh() {
        List<Vector3> verts = new List<Vector3>();
        meshFilter.mesh.GetVertices(verts);

        for (int v = 0; v < verts.Count; ++v) {
            // find which corner vert belongs to by find which Hex.CornerOffset it's closest to
            int index = 0;
            float distance = 999999f;

            for (int c = 0; c < 6; c++) {
                Vector2 cornerPos = Hex.CornerOffset(c, SettingsStatic.hexRadius);
                float dist = Vector2.Distance(cornerPos, new Vector2(verts[v].x, verts[v].z));

                if (dist < distance) {
                    distance = dist; 
                    index = c;
                } 
            }

            verts[v] += new Vector3(cornerOffsets[index].x, 0f, cornerOffsets[index].y);
        }

        meshFilter.mesh.SetVertices(verts);
    }

This line.

meshFilter.mesh.SetVertices(verts);

Does not work on the water hexes but does on the land hexes. I do not understand why. Both meshes are marked as read/write. The only difference is the water hex meshes are assigned to the meshfilter and the land hexes are assigned in the unity editor.

I solved my problem by copying the vertex colors instead of the mesh.