Swapping Materials on a SkinnedMeshRenderer?

Can anyone show me an example of how to do this?

I’m having trouble getting it to work…
This is what I tried, but it doesn’t change anything. (smr = the SkinnedMeshRenderer on my model)

Material mat = (Material)Resources.Load ("Materials/SomeMaterial");
smr.materials[0] = mat;

Is it possible that changing the material dynamically doesn’t change the texture that is assigned to the material on the SkinnedMeshRenderer? Do I need to change both?

EDIT:
Found this which is a little helpful, but I only want to change 1 material on a long list, not all of them. I really don’t want to reference each material for each part and reassign them all at once.

1 Like

Nevermind, I got it working. I just assigned all the materials to a new array, swapped out the one I wanted, and then reassigned the array. Kind of dumb that it has to be done this way though…

Material[] mats = smr.materials;
Material mat = (Material)Resources.Load ("Materials/SomeMaterial")
mats[0] = mat;
smr.materials = mats;
3 Likes

Perhaps you can just use smr.material = mat. I don’t know if you have to destroy it too, but from the docs it seems so:

public Material[] NumMat;
gameObject.GetComponent<SkinnedMeshRenderer>().materials = NumMat;

Thank you friend for this!

Thank you very much! It’s so helpful!:smile: