Changing MATERIAL not working, player is pink?

Okay, I asked a while ago how to update player names, and now I’m trying to make a skin system, but for some reason changing the material doesn’t work, it doesn’t assign a material to mesh renderer, same thing when I try to change the texture, it doesn’t get assigned at all…
I have no idea why it’s not working, as it shouldn’t be much different from changing the name, here’s the code:

using UnityEngine;
using System.Collections;
using UnityEngine.Networking;
using UnityEngine.UI;
public class Player_NameMaterial : NetworkBehaviour {
    public string playerName;
    public Material[] skins;
    public Material playerSkin;

    void Start(){
        playerName = PlayerPrefs.GetString("Name");
        playerSkin = skins[PlayerPrefs.GetInt ("ActiveSkin")];
        CmdSendNameToServer(playerName);
        CmdSendSkinToServer(playerSkin);
    }

    [Command]
    void CmdSendNameToServer(string nameToSend)
    {
        RpcSetPlayerName(nameToSend);
    }
    [Command]
    void CmdSendSkinToServer(Material skinToSend){
        RpcSetPlayerSkin(skinToSend);
    }
   
    [ClientRpc]
    void RpcSetPlayerName(string name)
    {
        gameObject.transform.FindChild("Canvas").transform.FindChild ("Text").GetComponent<Text>().text = name;
    }
    [ClientRpc]
    void RpcSetPlayerSkin(Material skin)
    {
        gameObject.GetComponent<MeshRenderer>().material = skin;
    }

}

Why are you sending the “Material Skin” ?
The server should already know the available skins, then the client tells the server what skin to choose from that list.
Just send the ActiveSkin int, then apply that one from the skin list.

public Material[] skins;
public int playerSkin;

void Start(){
playerSkin = PlayerPrefs.GetInt("ActiveSkin");
CmdSendSkinToServer(playerSkin);
}

[Command]
CmdSendSkinToServer(int playerSkinInt){
RpcSetPlayerSkin(playerSkinInt);
}

[ClientRpc]
RpcSetPlayerSkin(int playerSkinInt){
gameObject.GetComponent<Renderer>().material = skins[playerSkinInt];
}
1 Like

Okay, I’m retarded, have no idea how I didn’t figure that one out…
Thank you very much!