Don't know how to serialize Material

I have a code to set the material of a SkinnedMeshRenderer of a player randomly :

private void SetRndSkin(Material material)
    {
        meshRenderer.material = material;
    }

    [ServerRpc]
    private void SetRndSkinServerRpc(Material material)
    {
        if (!IsLocalPlayer) SetRndSkin(material);
        SetRndSkinClientRpc(material);
    }

    [ClientRpc]
    private void SetRndSkinClientRpc(Material material)
    {
        if (!IsLocalPlayer && !IsServer) SetRndSkin(material);
    }

But I get error

Don’t know how to serialize Material - implement INetworkSerializable, tag memcpyable struct with INetworkSerializeByMemcpy, or add an extension method for FastBufferWriter.WriteValueSafe to define serialization.

How can I fix it

When you pass a material to a function, you actually pass a reference to it – an address in the system’s memory, and so something that is inherently local. Instead, make sure that each client already has a local reference to the material (for example load in an array of materials from your Resources folder in Start()), and when calling the client or server Rpcs pass in the name of the material that you want loaded, or an index to it.

So I did that, but I still get the error. So I decided to use int instead of materials in the functions parameters. Now, when a client join, the host get the error “Object reference not set to an instance of an object” at the line where meshRenderer.material is changed