- Home /
How to create a procedural mesh with multiple materials?
I'd like to create a procedural mesh that makes use of multiple materials. How can this be done? I don't see any way from the mesh API to be able to change the material assigned to triangles? I understand the materials are set in the MeshRender, but how does the material renderer know which material to assign during rendering the different parts of the mesh?
this is what all of you are looking for:
https://answers.unity.com/questions/1436857/small-submesh-example.html
don't forget to add the Mesh.Clear(); at the top and not accidentally erase the Mesh.subMeshCount; like I was doing.
Answer by Eric5h5 · Apr 23, 2010 at 03:55 PM
Use Mesh.subMeshCount and Mesh.SetTriangles(), and assign materials with Renderer.materials. They go in order (the first material goes with the first submesh, etc.).
Your answer
![](https://koobas.hobune.stream/wayback/20220612184417im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Artifacts / Stretch Marks in Mesh Manipulation 0 Answers
Displaying precision edges of a mesh at runtime? 0 Answers
Procedurally generated mesh randomly appearing invisible 2 Answers
Flattening a mesh based on hit.point 1 Answer
Mesh return vs out Mesh 2 Answers