What is a submesh?

Hello,

I’m sorry this is probably a very dumb question but: what is a submesh?
The unity docs weren’t very clear on this one…

anyway thanks!

Each submesh is a separate list of triangles in the Mesh. This allows you to address that set of triangles separately...for example you can give different submeshes different materials.

1 Answer

1

Exporting an object with separate materials will give you separate submeshes. Such as in 3ds Max, you would apply different materials to either separate faces or objects as a whole. The polys sharing the same Mat on export will be grouped as a single submesh.

They appear as:

Element 0
Element 1
And so on.

If you want to check how many submeshes there are you can toss this code on (ignore the plural if it’s only 1 :P),

#pragma strict

function Start() {
		var mesh : Mesh = GetComponent(MeshFilter).mesh;
		Debug.Log(mesh.name + " has " + mesh.subMeshCount + " submeshes!");
	}

Submeshes can be made in code as well… but I’d stick to dropping different materials down in the 3d software.

ahhh thanks! what I tought it was :) thank you!

is this true? I thought submeshes were defined by their material id. I'm staring right now at a tree with a submesh 0 that's a trunk and a submesh 1 that's about 500 seperate objects.

It used to be that you could separate objects in the 3d application without adjusting materials... unless I'm mistaken.. Back some time ago I exported the separate spheres with the same MAT and got a variation of submeshes. At any rate, you have to apply multiple materials before exporting to get multiple submeshes. Regardless of how many material IDs your polys are sorted into. If they have the same MAT they'll be one submesh. I'll edit the answer so it's less confusing. Hope that helps!