- Home /
Unity on iOS - Specular Shader
I'm creating materials in script and assigning them to objects in my scene and have not experience any problems on OSX/Windows, but when I build and deploy to iOS I am getting a crash in my coroutine that loads/creates scene resources.
The crash happens when creating materials, and it doesn't crash on the first material (which uses a mobile/bumped specular shader.)
The crash happens on the second material in the Material constructor using Shader.Find( "Specular" )
I'm not aware of any restriction on using non-mobile shaders (not withstanding performance concerns of course), so I am stumped as to why this is crashing.
I've not spend anytime debugging with XCode before so I am having a hard time finding the culprit error on "Material.cpp line 268" when my XCode project doesn't have *.cpp files and doesn't have any files named material with any extension...
I'm virtually certain this is some dumb "welcome to Unity iOS you noob" issue.
Anyone...?
Here's the offending portion of code right up until what XCode is telling me is the crash source:
//Set materials for the frame
l_oFrameRenderer.material = new Material( Shader.Find( "Mobile/Bumped Specular" ) );
l_oFrameRenderer.material.name = "Titlebar Frame Material";
l_oFrameRenderer.material.SetTexture( "_MainTex", l_oLeatherTexture );
l_oFrameRenderer.material.SetTextureScale( "_MainTex", new Vector2( 7.0f, 7.0f ) );
l_oFrameRenderer.material.SetTexture( "_BumpMap", l_oLeatherNormalMap );
l_oFrameRenderer.material.SetTextureScale( "_BumpMap", new Vector2( 7.0f, 7.0f ) );
//Set materials for the inset - POP - Exception when the following line executes...
l_oInsetRenderer.material = new Material( Shader.Find( "Specular" ) );
Checking the return value of Shader.Find( "Specular" ) reveals that the value is NULL...
Is there some sort of packaging magic I need to enable to put the default shaders on an iOS device? It seems that the ones in the 'mobile' subdirectory are automatically deployed... Anyone know where this is configured...?
Hmmm... I wonder if it is because it isn't referenced anywhere outside of my scripts. I have a default material with the $$anonymous$$obile/Bumped Specular on it, and that one doesn't seem to be missing. Will try adding a material with Specular on it...
Answer by hkessock · Dec 28, 2013 at 12:50 AM
I don't know if this is a bug or a procedural error on my part, but the solution to this problem is to simply create a dummy material in your project that references each shader you plan to make use of from script. Sounds like bug, but a bug resulting from the Unity team just not having the luxury of looking around for stuff to finish adding ;).
So, remember folks, if you're going to create materials from script, make sure those shaders were referenced somewhere in your project outside of a script. Then again, I may be missing some simple method of letting Unity know that I want to use these shaders.
it is documented that resources are included in the package based on the hierarchies in scene files. so if its not referred to in any of those it won't get included unless its in one of the special paths that unity always includes - which includes at least Resources and Strea$$anonymous$$gAssets at least.
also don't cut the unity guys too much slack. this isn't a bug, but they also have imo totally failed to deliver a particularly good game engine to go with an otherwise fantastic editor.
Your answer

Follow this Question
Related Questions
iOS DepthTextureMode.DepthNormals mode support 0 Answers
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
Alternatives for using vertex colors + vertex lighting, IOS 1 Answer
Do i need to make asset bundles with upgraded Unity version? 0 Answers
Meshes not being rendered on iPhone 5, but working on any other iOS device 0 Answers