• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
2
Question by GameDev_Chuck · Apr 03, 2015 at 05:00 AM · materialpink

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!

Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Ether IT · Jul 30, 2015 at 12:50 PM 0
Share

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

avatar image GameDev_Chuck · Jul 30, 2015 at 11:24 PM 0
Share

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!

4 Replies

· Add your reply
  • Sort: 
avatar image
21
Best Answer

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.

alt text


toon.jpg (12.0 kB)
Comment
Add comment · Show 4 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image GameDev_Chuck · Apr 03, 2015 at 03:59 PM 0
Share

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!

avatar image GameDev_Chuck · Apr 08, 2015 at 01:42 AM 0
Share

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!!!

avatar image GameDev_Chuck · Apr 08, 2015 at 05:20 PM 0
Share

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!)

avatar image SimRuJ · Oct 24, 2018 at 02:50 PM 0
Share

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)!

avatar image
10

Answer by mian_abdul · 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.

Comment
Add comment · Show 4 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image nickeeromo · Aug 24, 2017 at 02:28 PM 0
Share

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!

avatar image SirDef11 · Oct 05, 2017 at 04:40 PM 0
Share

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...

avatar image bryner · Feb 07, 2018 at 12:15 AM 0
Share

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.

avatar image Phelanslim · Jul 29, 2019 at 05:20 PM 0
Share

It was stupid easy but could not figure out how to reset everything. Thank you!

avatar image
7

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.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image sunderplugs11 · Jun 11, 2016 at 06:41 PM 0
Share

what if Im only using default Unity UI components, and I have included them anyways?

avatar image
0

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.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

13 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Can't get highlight to work when mousing over object.. 0 Answers

Strange behaviour with reflections 1 Answer

Trying to change texture in Runtime - it becomes pink? 2 Answers

3d platform tutorial 1 Answer

Unity 5 - New project, default shaders are pink? 8 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges