Shaders do not get copied to runtime?

I am at a loss to explain it otherwise…

I have this code in my project

  `Shader shader1 = Shader.Find (mt);`

…where mt = “Self-Illumin/Diffuse”, in the editor it works just fine but when I build the project, the code fails at that point and shader1 is null. As soon as I try to assign shader1 to my object I get a null exception warning.

where mt = “Diffuse” all works well… So what do I do? Why is this breaking? Does it really not get copied over? How can I force it to be included in the build?

Or is it a case of the path / name of the shader being differnt at design time and runtime? Cause that makes no sense…

Any ideas?


Never mind… Found the answer while typing the question.

Since there is no object in the game that has the shader assigned manually, Unity does not copy the shader into the build. By manually assigning something in the game the self illuminated shader, the runtime loading thereof works.

Or, a better solution is to go EditProject SettingsGraphics and add the shaders you need to the “Always Included Shaders” list.