Setting emission color programatically

I have tried searching for this, but cannot find any solution.
I’m setting the color of each object as such:

Color color = Color.red;
float f = 0.4f; 
GetComponent<Renderer>().material.SetColor("_EmissionColor",color*f);

However, in the game the color is not set unless i select the object and expand the material component.
[I made a gif illustrating what I mean.][1]

I have tried using the DynamicGI, based on issues that were kind of similar, but nothing works. However, seeing that clicking the material in the unity editor causes it to be updated, the change seems to be registered. The updated materials are just not automatically applied.

EDIT:
Finally, after searching for altogether probably 8 hours, I found the solution. If you have the same issue, add

material.EnableKeyword("_EMISSION"); 

after setting the emissioncolor :slight_smile:
[1]: http://i.imgur.com/dQKeyBN.gif

I solved the problem. Turns out I had to also set material.color, in addition to the emissioncolor.

i.e:

void Start(){
    renderer.material.color = color;
}
void Update(){
    f = getIntensity();
    Color color = Color.red * f;
    renderer.material.SetColor("_EmissionColor", color);
}

Finally, after searching for altogether probably 8 hours, I found the solution.
If you have the same issue, add
material.EnableKeyword(“_EMISSION”);
after setting the emissioncolor :slight_smile: