Combine meshes with different materials

Hi

Firstly, I know this question has been asked several times but I can not find anything that works. Most of the time they say use submeshes so I did (I think) and nothing happened. So that’s why I ask this now.
Now for the problem itself.

So I have a few cubes made out of quads and they each have different materials. I would then later want to combine all those quads to a single mesh. I got the combining part working good but the materials do not work. As I said before, most of the answers said you should do “CombineMeshes(combine(CombineInstance), true);” but this doesn’t work. So how can I combine my meshes and keep the materials in the right place?

And for the code I am using, just go over to Unity - Scripting API: Mesh.CombineMeshes It is the exact same code.

Thanks in advance!

Well it’s not directly possible to combine meshes (into one) that use different materials. You can make submeshes but they would again cause you a lot of DrawCalls and SetPass calls. The reason is obvious each mesh has its own UV channels or Texture coordinates that are tailored to match a specific material having a specific texture applied on it. You can’t use a material designed to be used on a gun to be used on the face of a soldier and vice versa. You might have heard of Texture Atlasing or Texture Arrays they are the only solution to this problem but they are not simple to achieve.


You can check out my tool on the unity asset store “Poly Few” which is a complete optimization solution for Unity aimed at making high quality complex 3d scenes render efficiently. With integrated features like mesh simplification, automatic LOD generation, mesh combining and material combining, you can greatly improve the performance of your game by lowering the Polygon Count, DrawCalls and SetPass calls with a few clicks and, without the need of writing even a single line of code.