How to access properties of an object set in the Inspector

I’m new to Unity so I’m still struggling to understand how the inspector and scripts interact with each other. For instance, I have a button, and in the inspector, I set the image color to blue, and I want to fade that blue button to transparent using another script FadeScene.

My code:

public class ButtonFade : MonoBehaviour
{

    private FadeScene fadescene;
    private Color imagecolor;
    private Image image;
    private Button button;


    // Start is called before the first frame update
    void Start()
    {
        fadescene = FindObjectOfType<FadeScene>();
        button = GetComponent<Button>();
        image = button.GetComponent<Image>();
        //imagecolor = image.color; I added this line to try and get it to set the color to itself, but it didn't change anything
    }

    // Update is called once per frame
    void Update()
    {
        float alpha = fadescene.currentAlpha;
        imagecolor.a = alpha;
        image.color = imagecolor;

    }
}

This code gives me a null reference exception at image.color = imagecolor

1. Identify what is null
The button.image.color property.

2. Identify why it is null
I don’t know, it has a value set in the inspector and when I run the game, it is blue, so it has an initialized value, but I don’t know how to access that value from a script.

3. Fix that.

I’ve also made sure that the script is attached the button object.

It can only be the image variable, since it is being used to “point at” the color field.

Referencing variables, fields, methods (anything non-static) in other script instances:

https://discussions.unity.com/t/833085/2

https://discussions.unity.com/t/839310

REMEMBER: it isn’t always the best idea for everything to access everything else all over the place. For instance, it is BAD for the player to reach into an enemy and reduce his health.

Instead there should be a function you call on the enemy to reduce his health. All the same rules apply for the above steps: the function must be public AND you need a reference to the class instance.

That way the enemy (and only the enemy) has code to reduce his health and simultaneously do anything else, such as kill him or make him reel from the impact, and all that code is centralized in one place.