- Home /
Emission changes in script don't show in game
I have feature where the user should be able to highlight an object where the material's emission value is pingpong'd to make it pulse. Originally I did this through animators which worked, but I need to make it more modular so I'm trying to do it through script. My code is currently as follows:
void Awake () {
rend = GetComponent<SkinnedMeshRenderer>();
foreach (Material mat in rend.materials)
{
mat.EnableKeyword("_EMISSION");
}
}
// Update is called once per frame
void Update () {
foreach(Material mat in rend.materials)
{
float intensity = Mathf.PingPong(Time.time, 1);
Color newColor = Color.yellow * intensity;
mat.SetColor("_EmissionColor", newColor);
mat.EnableKeyword("_EMISSION");
}
}
I've read a lot of posts about enabling the keyword before using it, but in the game and editor windows the emission doesn't show up at all. The weird thing is though, that if I click on the object in editor and expand the material's window, it will update the preview of the material for that frame. So it's obviously running the script and applying the change to emission at the material level, but those changes aren't reflected on the actual scene or game object level. Any ideas or similar experiences?
Here's some frames of toggling the material window:
Hi, were you ever able to solve this? I'm having the same issue.
Your answer

Follow this Question
Related Questions
different material for multi camera 1 Answer
Skybox material not working 1 Answer
How to bake metallic reflexion from self illuminated static objects ? 0 Answers
Texture Stretching Not Tiling (HDRP) 0 Answers
Mipmap view not working in editor. 0 Answers