- Home /
Shader Missing in Builds When Called From Shader.Find("")
I have a script that draws up a reference to a shader by name via Shader.Find(), and it displays fine in the editor, yet when I build it for the web player OR standalone PC the object displays in solid pink. Thus it appears that the builder doesn't know it needs to be included in your build. Is there a way to mark it to be force-included?
(I tried to edit the question with this new realization but it seems the forum is broken and won't apply editing changes.)
I have a script that draws up a reference to the shader by name via Shader.Find(), and so that is the only reference to it from the program - thus it appears that the builder doesn't know it needs to be included in your build. Is there a way to mark it to be force-included?
keep ur shader in resource folder it will be included no matter wat happens
Answer by Eric5h5 · Mar 01, 2012 at 03:17 AM
Nothing to do with 3.5; the shader needs to be included somehow that forces it to be part of the build. It's in your project, so it will always work in the editor. Finding things with strings won't do it, since it's very hard to tell what all possible combinations are. i.e., Shader.Find("foobar");
could be done as var a = "foo"; var b = "bar"; Shader.Find(a+b);
. So Shader.Find won't cause a shader to be included, since Unity doesn't know it's being referred to. Instead, use the shader in a material on some object that's in the scene, or use it in a material that's in the Resources folder, since everything in Resources is always included whether it's used or not.
Looks like we were posting answers at the same time. Good call.
Answer by blitzen · Mar 01, 2012 at 03:20 AM
Solved as per a related post by placing the shader asset in Assets/Resources, which ensures it gets included in builds even when not directly linked to.
Where are the built-in shader assets? Can you get at them without downloading their source code?
The way I typically get built-in shaders into my project is by assigning them to materials that I don't actually use, and them putting those materials into a Resources folder. There must be a better way?
Shavais: Not that I know of. Both for built-in shaders and built-in GUI skins, you seem to have to download them separately. A slight inconvenience, yes.
Answer by jethrogillgren · Feb 08, 2018 at 06:40 PM
The new answer for Unity 2017:
Shaders can be forced included using Project Settings>Graphics>"Always Include Shaders"
In Unity 2021 you can get there through: Edit>Project Settings>.... Or also: File>Build Settings>Player Settings>Graphics>Always Included Shaders (increase the size and pick the shader for the new element)
Your answer
Follow this Question
Related Questions
Why won't my specular shaders work in the WebPlayer? 0 Answers
What is the most common shader model (2.0+,3.0+,4.0+) for unity web player users (or an average) 1 Answer
How to force the compilation of a shader in Unity? 5 Answers
Only on Mac OSX: Rendering/shader error within webplayer 0 Answers
Why can't I build Web Player in Unity while I have no problems with building standalone versions? 2 Answers