- Home /
Assign new material to submesh?
If I have a object with several submeshes, and all those submeshes are using the same material, how can I pick out a specific submesh and set its material to something else? I guess im mostly confused how you would be able to find the submeshes. If the submeshes used different materials I could simply get array of materials and change the one I want. But I cant do that in this case because the material is the same for all submeshes.
Answer by Eric5h5 · Jan 01, 2014 at 02:22 AM
var allMaterials = renderer.materials;
allMaterials[numberToChangeHere] = someMaterial;
renderer.materials = allMaterials;
As I said, this method wont work in this case because I want to assign a new material to only one if the submeshes. This would change it for all submeshes, because theyre using the same material at start.
No...I understood your question. It won't change it for all submeshes, only the one you pick. Each entry in the array corresponds to a submesh.
So that var creates an array of materials even if some are the same?
I'm not sure you actually are talking about submeshes. Either that or you're not using an instance of the material, because if you change a material (not an instance) then naturally everything that uses that material will change.
Every object is a separate draw call regardless of sharing a material, unless you use dynamic or static batching. Although I don't know if objects with submeshes batch (I would guess not).
Your answer
Follow this Question
Related Questions
Do submeshes get sorted properly for transparent materials? 0 Answers
How does submesh index map to material? 1 Answer
How to work with submeshes in editor 1 Answer
Combining blender submeshes 3 Answers