SetTriangles Method for Multiple Materials on Procedural Mesh

Hello,

I’m making a procedural mesh, and I currently don’t know how to apply multiple materials to that mesh.

I looked online, a few very brief forum posts mentioned using mesh.SetTriangles().

I haven’t seen an implementation of this yet, so I’m a little confused as to how to actually use this method.

So far I’m getting bad results!

In the attached image, I broke up my triangles array which was an array of ints. I then set triangles for each part of the mesh I wanted governed by a different material.

No luck so far. Any tips greatly appreciated.

this is what all of you are looking for:

don’t forget to add the
Mesh.Clear(); at the top and not accidentally erase the Mesh.subMeshCount;
like I was doing.

1 Like

thank you for this Mexicano!
after creating a new Mesh, do Mesh.Clear() before setting any vertices, normals, UVs or triangles.
for some reason this works…
Mesh mesh = new Mesh();
mesh.Clear();
mesh.SetVertices(vertices);
etc…