- Home /
 
Shaders in Project Aren't Transferring Over to .EXE
Hello. I'm creating a game, and at one point in the game, all objects in the screen fade out. To do this, I'm using a loop to assign all objects a temporary transparency shader, then turning down the alpha property. It seems to work perfectly when I'm inside the Unity Editor. However, if I try to build an executable and run it, all the objects turn pink when they are supposed to be fading away. I know this means that it can't find the correct materials, but they're all in the project, so I assume it is a problem with Unity finding the shaders. To clarify, I'm creating Shader variables, then assigning them in the Start function. Thanks in advance for the help. Code below:
 Shader shaderTrans;
     
 void Start () {
     shaderTrans = Shader.Find ("Transparent/Diffuse");
     shaderIlluminate = Shader.Find ("Self-Illumin/Diffuse");
 }
 
 void Update () {
     objList = GameObject.FindObjectsOfType (typeof (GameObject));
     foreach(GameObject obj in objList){
         if(obj.renderer){
             foreach (Material mat in obj.renderer.materials){
                 mat.shader = shaderTrans;
                 Color oldColor = mat.color;
                 mat.color = new Color(oldColor.r,oldColor.g, oldColor.b, alphaFade);
             }
         }    
     }            
 }
 
              Answer by ArkaneX · Mar 28, 2014 at 09:03 AM
According to Shader.Find reference:
When building a player, a shader will only be included if it is assigned to a material that is used in any scene or if the shader is placed in a "Resources" folder.
Additionally, I think you can force shader to be included in the build, by going to Edit->Project Settings->Graphics, and adding your shader to the array. I've never tested this though.
Your answer
 
             Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Painting materials onto meshes at runtime? 1 Answer
Animate changing the material 0 Answers
UI Text - changing material instance 1 Answer
Cannot change material on build 1 Answer