- Home /
Android sprite shaders missing (pink) change via code
Hey, I was working with unity's sprite/diffuse shaders and they work just fine in the editor. But when I make them in android standalone and test them in my Samsung Note 2 they appear pink, which is I reckon missing textures or unsupported shaders. I am changing it from a supported texture using this code
void Awake()
{
daynm = GameObject.Find ("DNM");
if (daynm.GetComponent<DayNightManager> ().isNight == true) {
gameObject.renderer.material.shader = Shader.Find("Sprites/Diffuse");
}
}
Well, pink normally means the shader is not found or not supported. Do you have any in the player log file?
Answer by lucax · Nov 25, 2014 at 05:42 AM
Alright, I found a foolproof fix. Create a folder called Resources in your Assets. Now make a new shader. Copy the code of your shader in it, change the name as of your new shader in the code (it's in first few lines you can't miss it). Save it.
Now in the the code, call for the shader as normal. It should work fine.
gameObject.renderer.material.shader = Shader.Find("MyShader");
Answer by tanoshimi · Nov 23, 2014 at 08:12 PM
If you're changing shaders during runtime, you need to make sure that they're being included in the build (Go to Edit -> Project Settings -> Graphics -> Always Included Shaders and make sure that Sprites/Diffuse is listed there).
The only shaders that Unity can resolve and include at compile-time are those that are initially assigned to objects.
By the way, YES. I am trying to change them in runtime.
Even tried to use the compression setting while building for the device, which took a good half hour, but that too didn't make any difference.
This worked for me, since my shader was never used for anything in the scene except when called upon by code.