hey guys, how do i change a single material in a object that has many materials with skinnedmeshrenderer?

i wrote a code to change one material of the mesh
but when i do it it only changes the “Element 0” material and i want to change the “Elemment 1” material
how do i do to change the second material of the mesh?
in code

Mesh.GetComponent().material = mat1;

You can’t change an individual material. Instead, copy them all out, update the one you want then write them all back.

    Material[] allMaterials = gameObject.GetComponent.<Renderer>().materials;
    allMaterials[4] = material6;
    gameObject.GetComponent.<Renderer>().materials = allMaterials;

Documentation is here. It says: “If you want to change some materials in it, get the value, change an entry and set materials back.”