Change linerenderer color to custom shader's color

Hi!

I have a custom shader and I want to change the linerenderer’s color to the shader of the sphere at runtime, but I don’t know how to do it. This is my code:

[SerializeField] GameObject sphere;
[SerializeField] GameObject link;
private LineRenderer lineRenderer;

private void Awake () {
    lineRenderer = link.GetComponent<LineRenderer>();
    lineRenderer.positionCount = 2;
}

private void Start () {
    CreateColor();
}

private void CreateColor()
{
   lineRenderer.startColor = sphere.GetComponent<Renderer>().material.color;
   lineRenderer.endColor = sphere.GetComponent<Renderer>().material.color;
   Instantiate(link, Vector3.zero, Quaternion.identity, sphere.transform);
}

You need to apply a material to the LineRenderer and set the colour of that material, instead of setting the startColor and endColor variables like so:

lineRenderer.GetComponent<Renderer>().material.color = sphere.GetComponent<Renderer>().material.color