renderer.materials not working.

Hey guys, here is my code.

function Start() {

    selection = Random.Range(0, allBTextures.Length);
    
    skeleton = this.transform.FindChild("skeleton").transform.GetComponent(SkinnedMeshRenderer);
    bodyMat = allBTextures[selection];
    headMat = allHTextures[selection];
	skeleton.materials[0] = bodyMat;
	skeleton.materials[1] = headMat;

}

The problem is that the materials don’t change.

If I change it to ‘skeleton.material = bodyMat’ then it works but of course only changes the first material, leaving the second on the same.

With both set to ‘skeleton.materials’ it doesn’t throw any errors rather it just doesn’t change the material. Why is this? As far as I knew this was meant to worked.

Cheers.

Try like this:

Material[] mats = new Materials[]{bodyMat, headMat};
skeleton.materials = mats;

This is the same with all Unity objects when you try to access them with .