11

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

2 Answers 2

29

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

Sign up to request clarification or add additional context in comments.

Comments

2

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.