Reputation: 5243
I am new in Unity and there is something looks weird to me. I created a UnlitTextureYUV.shader
file then I use it in my script like this
...
meshRenderer.material = new Material(Shader.Find("UnlitTextureYUV"));
...
Then in editor I click on run button and I see that everything is working properly, ok. Then I click File->Build&Run
and I get an error ArgumentNullException
that means shader not found.
I tried to find out what is going on and found such answer on Unity community
https://answers.unity.com/questions/1147277/textures-from-local-works-in-editor-missing-in-bui.html
As far as I understand in order to use shaders in build dynamically I need to create dummy material add texture to it and even create dummy object (disabled) and add this material to this object. In this order my shader will be included in build and I will be able to find it dynamically in code by invoke this method Shader.Find("UnlitTextureYUV")
.
Question is - is there more straight way to include shader in build? Why I need to create dummy objects in order to include this file in build? Or I miss something?
Upvotes: 1
Views: 3146
Reputation: 1257
You have to add all your shaders to Unity's 'Always included shaders' list in the graphic settings.
Upvotes: 4