Shaders not loading properly in iOS Unity builds

September 24th, 2014 by Alan MacGregor Leave a reply »

It’s that classic routine everything works in your game but when deploying to the device everything goes wrong, this time its due to unity’s shaders, you’ll most likely see something like this inside of the ios’s console logs

  at UnityEngine.Material..ctor (UnityEngine.Shader shader) [0x00000] in <filename unknown>:0

So whats going on here, we can see that the error is clearly with the shaders and the issue is that it can’t seem to find it. Let’s fix it

What should happen but doesn’t work
Shaders take up disk space and theres an awful lot of shaders that you can add, unity gets around this by only including shaders that you use in the scene. However some times you only mention the shader in the code so you need to inform unity to include specified shaders this can be done by going into:
Edit -> Project Settings -> Graphics
In this menu you can amend the array to include your added shaders, however closing the application and rerunning it shows the shaders no longer there so essentially nothings being saved, somethings going wrong here, and this is why you are getting the issue

The fix
Basically these can be fixed by ensuring shaders are available in the scene in edit mode, create a new material for each shader you want to use and add each to an object, I prefer to add these as child objects to parent with an empty scale, this way you can store it as a prefab and use it on multiple scenes.

Once built the ios device should be able to find the shader and your game can load again, happy days


Leave a Reply