Build not including custom shader

Hey all,

I’m building a game with a custom shader. The problem is that when I build it it doesn’t include the custom shader and all the meshes that use it look purple.
The shader works in the editor though.

This is how I link the shader to my meshes.

shader = Shader.Find("MyShader");
meshRenderer.material.shader = shader;

Put your shader in a Resources folder to ensure it gets into the build. (Or have a material in the scene somewhere that uses it).

My 2 favourite ways:

  1. Go to Edit > Project Settings > Graphics and add your shader to the Always Included Shaders
  2. Put your shader in a folder called Resources and load it with the Resources.Load API.

Unless Unity finds a link to the shader it will leave it out of the build, so, yes you can force the inclusion of that shader by creating a Material that uses it but you’d be creating a redundant resource so I prefer the two methods above.