Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting emission color in unity

Tags:

c#

unity3d

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.color = color;
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.

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.

like image 883
Grisungen Avatar asked Nov 12 '15 11:11

Grisungen


1 Answers

After many hours of searching, I managed to find a solution just after posting this question.

To fix the issue, simply add

material.EnableKeyword("_EMISSION");
like image 194
Grisungen Avatar answered Sep 18 '22 01:09

Grisungen