Mesh polygons connect wrong at 256 or more Vertecies?

I fought with Unity to generate my Mesh a lot by know and Unity granted me a part succsess and I can generate Meshes to a length of 256 Verticies but after that Unity goes ‘f*ck you’ and my edges connect in a way that I dont get. (No errors what so ever)

void GenerateMesh()
    {
        triangles = new int[size * size * 6];
        vertices = new Vector3[(size + 1) * (size + 1)];

        for(int y = 0, i = 0; y < size; y++)
        {
            for(int x = 0; x < size; x++)
            {
                vertices[i] = new Vector3(x, noise[x, y] * 15, y);
                i++;
            }
        }

        int verts = 0;
        int tris = 0;

        for(int i = 0; i < size - 1; i++)
        {
            for(int j = 0; j < size - 1;j++)
            {
                triangles[tris + 0] = verts + 0;
                triangles[tris + 1] = verts + size;
                triangles[tris + 2] = verts + 1;
                triangles[tris + 3] = verts + 1;
                triangles[tris + 4] = verts + size;
                triangles[tris + 5] = verts + size + 1;

                tris += 6;
                verts++;
            }
            verts++;
        }

    }

    void UpdateMesh()
    {
        mesh.Clear();

        mesh.vertices = vertices;
        mesh.triangles = triangles;
       
        mesh.RecalculateNormals();
    }

You can copy and try it I am out of ideas

256 x 256 is 65536…

While @Kurt-Dekker is probably correct that this is the cause, the thread Google gets that information from is pretty old and I think predates mesh.indexFormat. Set that to Int32 before you start working on your vertices and you should be able to get more verts.

1 Like

Thanks I will try that

Thanks I thought it were 65,534 Polygons not vertices but now I know better must have messed something up

After looking how to change the IndexFormat to UInt32 I was able to scale my Mesh to 4096 Vertices. Probably could do more but generating it to that scale took 30 seconds. I have to do more optimization anyway so maybe I will generate even bigger Meshes in the future.
So glad you wrote that :slight_smile: