Material array not working,

Hi. I am having trouble with a project I’ve been working on. I have an object and I need it to change materials when the player collides with it. I followed a tutorial and it originally worked perfectly, but it just stopped registering the material array in the inspector one day and I can’t work out why. All the collisions and everything works it is literally just the array. Here is my code:

Material[] materials;
private Renderer rend;

void Start () 
{
    rend = gameObject.GetComponent<Renderer>();
    rend.enabled = true;
    rend.sharedMaterial = materials[0];
}

private void OnCollisionEnter(Collision col)
{
    if (col.gameObject.tag == "Player")
    {
        rend.sharedMaterial = materials[1];
    }
}

The problem may be in a different script. See if something else is fiddling with the render or material.

Changing material itself doesn’t have an issue. Below code should work.

    public Material[] materials;
    private Renderer rend;

    void Start()
    {
        rend = gameObject.GetComponent<Renderer>();
        rend.enabled = true;
        rend.sharedMaterial = materials[0];
    }

    private void OnCollisionEnter(Collision col)
    {
        Debug.Log(col.gameObject);

        if (col.gameObject.tag == "Player")
        {
            rend.sharedMaterial = materials[1];
        }
    }

If the OnCollisionEnter function is not called, there are 2 reasons.
First, the OnCollisionEnter function could not be called because of inappropriate collider&rigidbody setting. You can simply check it with Debug.Log() in OnCollisionEnter. About collision check this: Unity - Manual: Introduction to collision. Scroll down below and see collision action matrix.
Second, It is not called if you disabled physics collision between layers or colliders. Go to Edit/Project Setting/Physics and check Layer Collision Matrix. Also, check if you are using Physics.IgnoreCollision or Physics.IgnoreLayerCollision. Hope this helps you.