- Home /
Getting pink textures in build
Hi, In my game I'm attempting change materials on an object but am running into a strange issue. When I run the game inside the editor everything works as expected, however, when I make a build, all objects using the Toon/Basic Outline shader (part of the effects package in standard assets) turn bright pink. I've noticed that the build will work correctly if I only include one object that has the material changing script attached to it.
Here is the material changing script, it's loosely based off the Render.material example provided at http://docs.unity3d.com/ScriptReference/Renderer-material.html :
public class MaterialManager : MonoBehaviour
{
public Material normalGhostMaterial;
public Material lightGhostMaterial;
public Material darkGhostMaterial;
public float runForSeconds = 5;
private Renderer rend;
private float timer = 0;
private float blinkInterval = 0.4f;
private float lastBlinkTime = 0f;
private int blinker = 1;
void Start()
{
rend = GetComponent<Renderer>();
rend.enabled = true;
}
void Update()
{
checkTimesUp();
}
public void startRunning()
{
rend.material = darkGhostMaterial;
startTimer();
}
void startTimer()
{
timer = Time.time;
}
void checkTimesUp()
{
if (Time.time - timer > runForSeconds)
{
rend.material = normalGhostMaterial;
blinker = 0;
}
else
{
if (Time.time - timer > 2.5f && Time.time - timer < runForSeconds && Time.time > 5)
{
blink();
}
}
}
void blink()
{
if (blinkTimeChange())
{
blinker++;
}
if(blinker % 2 == 0)
{
rend.material = lightGhostMaterial;
}
else
{
rend.material = darkGhostMaterial;
}
}
void startBlinkTime()
{
lastBlinkTime = Time.time;
}
bool blinkTimeChange()
{
if (Time.time - lastBlinkTime > blinkInterval)
{
startBlinkTime();
return true;
}
else
{
return false;
}
}
}
I noticed in the sample on the render.material page that they use rend.sharedMaterial instead of rend.material. I tried this but it didn't fix anything. I've also tried the script with the Unlit/Color shader and it seems to work fine with that, but I'd still prefer to use the toon shader. At the moment, the materials I've created (with the issues) use a 'Toon/Basic Outline' shader with just the 'Main' and 'Outline' colors defined. There are options for 2D textures but I've left them set at 'None' (which has been working fine up till this issue). Anyway, as always, thanks for your time and words of wisdom!
Hi,
I have 3 $$anonymous$$acs. One of my shader was showing the pink texture issue when build into iPhone and iPad Air 2(metal), but no issues in ipod 5(OpenGL). $$anonymous$$y third $$anonymous$$ac was building the game without any issues until recently after I updated its OS and xcode.
After the update it started showing problem of bringing in the pink texture to the objects this shader is applied to. But everything works fine on my ipod 5.
I have tried almost everything like, Edit -> Project Settings -> Graphics, placing the shader in the resource folder, the materials are already in the sub folders of the resource folder. But I haven't tried what P$$anonymous$$GameDev_Chuck had told
Blockquote
Okay so I've been playing around with the Graphics settings a little more and it looks like if I set the Deferred option in Built-in shader settings to 'No Support' then my materials work across all scenes. I read up on Deferred shading in an attempt to understand why making this change fixed the problem, but, well... that stuff is way over my head. Basically as far as I can tell, it's just shading options. $$anonymous$$y game doesn't use shadows though so I'm setting both Deferred and Legacy Deferred to 'No Support' (Unless anyone thinks I shouldn't!)
Blockquote
as I did not understand how to do it and neither I found the option he has mentioned.
Can anyone help me out with this.
Thanks,
Gokul Elayadath
To get to those settings, Edit -> Project Settings -> Graphics. Then at the top of the inspector, under Built-in Shader settings, you'll have the 'Deferred' and 'Legacy Deferred' options where you can set them to either No Support, Built in Shader, or Custom Shader. I don't know of those will help you, but that's where they are. Good Luck!
Answer by tanoshimi · Apr 03, 2015 at 08:21 AM
This is expected behaviour - when compiling a build, Unity only includes those shaders that it knows are required (i.e. are assigned to a material in the scene). If you want to change a shader programmatically at runtime, Unity won't know to include that shader unless you explicitly tell it to.
To resolve this, go to Edit -> Project Settings -> Graphics and add the Toon/Basic Outline shader to the list of Always Included Shaders.
Tanoshimi you are the man! Your suggestion appears to have resolved the issue. A big thanks to AlwaysSunny as well. I attempted the dummy object approach but it still wasn't working for me. (I was probably doing it wrong). Anyway, thanks again to both you!
Hey tanoshimi,
So I hate to bug you again, but it appears the issue hasn't been fully remedied. Earlier, your solution worked fine when I just had one scene in my project. I've now implemented a state machine that transfers from a logo scene, to a main menu scene, and finally to the play scene. The state machine transfers from scene to scene as it should, but when it gets to the play scene, I lose all of the materials using the toon/basic outline shader. Any idea what's going on here? I also noticed, that if I make the play scene the first scene to load, then the materials work fine. Halp!!!
Okay so I've been playing around with the Graphics settings a little more and it looks like if I set the Deferred option in Built-in shader settings to 'No Support' then my materials work across all scenes. I read up on Deferred shading in an attempt to understand why making this change fixed the problem, but, well... that stuff is way over my head. Basically as far as I can tell, it's just shading options. $$anonymous$$y game doesn't use shadows though so I'm setting both Deferred and Legacy Deferred to 'No Support' (Unless anyone thinks I shouldn't!)
Some of the hidden shaders are missing from that list (e.g. "Hidden/Internal-Colored"), you have to download them here (click on the "Downloads" dropdown of the version you want and pick "built in shaders") and add the ".shader" file to your "Resources" folder! This way they'll get exported with your build and are still accessible with "Shaders.Find()" afterwards. Important: Don't add the "Standard" shader (bug: click)!
Answer by MianAbdul · Jul 20, 2017 at 03:08 PM
Edit/ProjectSettings/Graphics. And Right Click at the top of the inspector page for built-in shaders and choose reset it should fix it for you automatically.
THIS is what worked for me. Using Unity 2017 and suddenly even regular button textures were rendering pink on Android, as well as a texture displaying WebCam feed. Thank you!
Finally, thankssss ^^
We should blame the unity devs, i mean : WHY ??? Why doesn't they fix those ugly bugs by themselves ? Omfg, the pink screen was the 10th hard bug i had, i swim in mud since weeks, for the most basic app with only UI elements... Nothing works, or maybe i'm the unluckiest man ever idk : you must install yourself the android sdks, then they dont work and you must downgrade them, then its your jdk wich doesnt work, then you have to downgrade it too, and you have to write yourself your Bundle Identifier because it's not working, then when you write a "é" in your folder's name, the apk doesn't want to build neither and you have to create a new project in another folder, and so on and so on... WEE$$anonymous$$S, weeks, i opened 150 internet tabs to fix all those bugs, so THAN$$anonymous$$S TO YOU PEOPLE ! :)
And now it seems to work on my smartphone, this pink was the last bug ^^ But now, I have to understand why my tiny app takes 32 F*$$anonymous$$IN SECONDS to launch as an exe on my windows 10 now, awesome... the 11th mega bug, and of course not the last...
I don't usually do this, but was willing to sign up, login, and up-vote this answer to encourage you that even though you posted this last year, I am thankful that you took the time to do so.
Thank you for such a simple and effective answer! The world needs more people like you.
God Bless.
It was stupid easy but could not figure out how to reset everything. Thank you!
Answer by AlwaysSunny · Apr 03, 2015 at 04:25 AM
The problem is most likely because of how Unity trims the fat when you build projects. Any asset which does not appear to be used will be left out, resulting in "Problem Pink" in the case of missing shaders, materials, or textures. If your only reference to them is in scripting, it won't detect that they're needed for the build.
Try putting all these special materials in the Resources folder. OR, an alternative that seems to work is, keep some deactivated dummy objects in your scene that use these special materials so Unity knows to include them in the build.
what if Im only using default Unity UI components, and I have included them anyways?
Answer by TheOtherJoJo · Feb 03, 2019 at 04:07 AM
My issue was that all the graphics was missing the sprites default shaders. I didn't do anything special, but for some reason when I created a new project and then reimported my asset, the sprite shaders were missing.
Answer by moony4 · Apr 03 at 06:25 PM
Using URP, when create object and set color through code this help me Fix it:
YourGameObject.GetComponent<Renderer>().material.shader = Shader.Find("Universal Render Pipeline/Lit");