Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

unity Shader returns a NULL when using Shader.Find

Tags:

unity3d

unity5

As stated here I am not the only one finding the following problem:

Shader.Find returns a Null.

In the link above they gave a solution by creating something(?) in the Resource Folder, but I am not sure I understand. First, is this necessary for all cases? (meaning Shader.Find does not work by itself?) Second, what should I add? An unlit shader?? a material? Very confused here

like image 613
KansaiRobot Avatar asked Sep 04 '17 08:09

KansaiRobot


2 Answers

I could solve the problem finally by doing the following:

First, go to unity editor: Edit->Project Settings-> Graphics Then in the inspector where it says "Always Included Shaders" add "Unlit/Texture"

Then change my Shader.Find code to read Shader.Find("Unlit/Texture");

With this it does not return null anymore

like image 164
KansaiRobot Avatar answered Sep 26 '22 02:09

KansaiRobot


You should add your shaders to any of the scene objects otherwise they work only in editor. Add your shader to Resource Folder or you can create new one.

In Resource Folder

RightClick -> Create -> Material When you select the material you will see the shader field in inspector,choose the suitable one for you.

For example: in my script;

var newMtl = new Material(Shader.Find("Standard (Specular setup)")) { name = materialName };

So I added the material and select Standard (Specular setup) as the shader.

like image 29
badcode Avatar answered Sep 24 '22 02:09

badcode