Changing Gradient colour on linerenderer at run time?

Is this possible?
I’ve set up two gradients

        gradientSighted.SetKeys
        (
            new GradientColorKey[] { new GradientColorKey(c1, 0.0f), new GradientColorKey(c2, 1.0f) },
            new GradientAlphaKey[] { new GradientAlphaKey(1.0f, 0.0f), new GradientAlphaKey(0.0f, 1.0f) }
        );

        gradientUnSighted.SetKeys
        (
            new GradientColorKey[] { new GradientColorKey(c3, 0.0f), new GradientColorKey(c4, 1.0f) },
            new GradientAlphaKey[] { new GradientAlphaKey(1.0f, 0.0f), new GradientAlphaKey(0.0f, 1.0f) }
        );

and I’m changing them in a small routine checking if something is ‘sighted’ like this:

       if (Physics.Raycast(transform.position, transform.TransformDirection(Vector3.right), out hit, Mathf.Infinity, layerMask))
        {
...
            lineGradient = gradientSighted;

        }

But it’s doing nothing. I can change fine in Start() and whatnot, any update() and it’s just not having it (so far).

lineGradient is an instance of sightRenderer.colorGradient (LineRenderer sightRenderer).

Thanks.

I’ve solved this by moving a few things round - a variable had found it’s way into start() and wasn’t accessible through the way I had declared LineRenderer. :stuck_out_tongue: