How do I change only the alpha value of the color of a panel?

//this works:
fadePanel.GetComponent().color = new Color(0, 0, 0, fadePanel.GetComponent().color.a + Time.deltaTime / fadeTime);

//this does not work:
fadePanel.GetComponent<Image>().color.a += Time.deltaTime / fadeTime;

I’m trying to modify the alpha value of the color of the image component in a panel. For some reason, I can modify the color in its entirety, but I can’t modify the alpha value alone. Is the alpha value read-only? If so, is there a shorter way to write the first option?

(the same thing happens with r, g, and b)


This is the error message I’m given:
Cannot modify the return value of ‘Graphic.color’ because it is not a variable (CS1612)

You can’t modify the individual values of the used colour, you can only set an entire colour object to it. So you need to create a new colour and set all the RGB values to the current values on the image, and a to your current value. Also as a general bit of unity advice, you want to avoid calling get component multiple times as it is quite slow to run:

//store image component so we don't need to get it multiple times
Image img = fadePanel.GetComponent<Image>();

//Set the new colour to existing values for RGB and the new value for a
img.color = new Color(img.color.r, img.color.g, img.color.b, img.color.a + (Time.deltaTime / fadeTime));