Search Unity

SetTriangles Method for Multiple Materials on Procedural Mesh

Discussion in 'General Graphics' started by devstudent14, Dec 6, 2019.

  1. devstudent14

    devstudent14

    Joined:
    Feb 18, 2014
    Posts:
    133
    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.
     

    Attached Files:

  2. mexicano

    mexicano

    Joined:
    Nov 12, 2013
    Posts:
    23
    Jilbarkus likes this.
  3. Jilbarkus

    Jilbarkus

    Joined:
    Oct 6, 2022
    Posts:
    6
    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...