Problem changing the alpha of a gameobject

I am struggling to change the alpha of a gameobject.
The material is of course transparent or fade, both fails.

the problematic code is in a loop changing the alpha of different gameobjects, and is basically like this:

sCm = subComponent.GetComponent<Renderer>().material; //outside of loop

 float alphaVal = 0f;
 Color newColor = sCm.color;
 newColor.a = alphaVal;
 sCm.SetColor("_color", newColor);
 print(sCid + ": should be " + alphaVal + ", tried to change to " + newColor.a + ", is actually " + sCm.color.a);

And the print reads: (component number): should be 0, tried to change to 0, is actually 1

The material.color shortcuts changes the “_Color” material property but you’re setting the “_color” (lower-case “c”) property. Property names are case-sensitive, so you’re setting one but reading a different property.

If you use material.color, you should use it to both get and set the color. Otherwise, use both material.GetColor and material.SetColor. I wouldn’t mix the two.

Ah, that makes sense… Thank you!

How do you change the value with material.color? i only got errors when trying to do that.

sCm.color = new Color(1, 1, 1, ((Mathf.Sin(Time.time) + 1) * 0.5f));