MissingComponentException occurs when applying alpha values to objects.

I found the following sample source on YouTube, and when I tested it, it worked well.

public class AlphaChange : MonoBehaviour
{
    [SerializeField] private Material myMaterial;

    private void Start() {
        Color color = myMaterial.color;
        color.a = 0.5f;
        myMaterial.color = color;
    }
}

I added the source to my project.

The script is as follows:

    public GameObject umbrella;
    Material umbrella_Material;
    Color umbrella_alpha_color;

    private void Start() {
        umbrella_Material = umbrella.GetComponent<Material>();
        umbrella_alpha_color = umbrella_Material.color;
    }

My project is as follows.

200520-question.png

GameObject: Umbrella has the following materials.

200521-question2.png

There is no problem when compiling, but the following error occurs when playing the game.

MissingComponentException: There is no 'Material' attached to the "Umbrella" game object, but a script is trying to access it.
You probably need to add a Material to the game object "Umbrella". Or your script needs to check if the component is attached before using it.
UnityEngine.Material.get_color () (at <d8d38b92d94a4ff8a91e61d39c6d19cd>:0)
SkillManager.Start () (at Assets/Scripts/Manager/SkillManager.cs:51)

You do not get the material directly from a gameObject, instead you need to grab it from its renderer.

//First get the Renderer of the umbrella Object
Renderer renderer = umbrella.GetComponent<Renderer>();
 
// Then get the material
umbrella_Material = renderer.material;