I modify the emission color of standard shader in my C# script code, it work in the editor view and game view, but if I make a standalone build, it dosen’t work at all, Is there anyone met this problem before.
My method of modify emission color is below.
render .material.EnableKeyword (“_EMISSION”); render .material.SetColor(“_EmissionColor”, tcol); It works well in the editor, but in standalone, take no effect. Please help!
Do you have the Emission Color of your material set to black in the Editor? If it’s set to black then the _EMISSION shaders will be stripped away at built time because _EMISSION is defined with shader_feature. This is an optimization. You can find more detail about this here: Unity - Manual: Using materials with C# scripts
Make sure the Emission Color is a non black color and you’ll be able to animate the color using the script.
Thanks to @argosy_ops_1 for posting this information in a reply in the unityAnswers section, thought I’d mention it here since it took me a while to find it myself. Here’s my step-by-step take on it:
Place empty cube somewhere in your scene.
Create a new material that uses a shader (like Standard or Standard (Specular setup) that matches that of materials you want to modify Emission Color for later.
Give the new material an Emission Color value higher than 0.
Apply the new material to the cube, then disable the cube through inspector.
Now, even after making a standalone build, you can modify the Emission Color for any material that uses the same shader as this “dummy material”, even if those materials didn’t have any Emission Color specified at build-time.
This seems very useful to me (I’m using Emission Color to highlight objects with mouse, for instance), but I am unsure about the potential negative effects this hack might have on performance, since @INedelcu mentioned that it works like this for optimization reasons…