Unable to change material color at runtime

material.color or material.SetColor does not work. Objects is a pool of Gameobjects(prefab) Tried mobile-diffuse and mobile-particles-alpha blended.

Objects[PoolSize].GetComponent<Renderer>().material.color = Color.cyan;

Primary goal is to be able to change alpha of material’s color. What is causing it?

@hgokturk

Hi. Your material shader should be such it supports transparency. Then you change it’s material’s color:

var col = new Color(1f,0f,0f,0.5f);
GetComponent<Renderer>().material.color = col;

You’ll have to change the color and alpha at once, as it’s a struct and then re-assign it. Here I made the color red and alpha 50% transparent.

Also, you probably don’t want to change colors of prefabs, but instantiated clones of those while in play mode.

@eses Yeah, that is actually clones of prefabs that i’m trying to change the color/alpha of. So i must find a good mobile shader which allows me to change the color right?

@hgokturk

I don’t remember if there is a transparency supporting mobile shader, but at least you can test this by setting your Material to use Standard shader and set it’s Rendering mode to Transparent. Maybe someone else can help you with the shader.