• 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
Question by GambitDev · Feb 15, 2017 at 07:38 AM · iosmaterialunity5texture2d

Texture appears Pink on Device (works on editor)

Im trying to apply a simple texture to a Gameobject (plane) that i have created during runtime. Im choosing a simple jpeg image stored in my "Resources" folder, loading it and trying to apply it as a texture.

Heres the following code snippet in my Gameobject class:

  Texture2D staticTex  =    (Texture2D)Resources.Load("test");
 
 Debug.Log("ULog Texture Size Width " + staticTex.width  + "ULog texture Size Height  " + staticTex.height);
 
 MeshRenderer renderer            =     plane.AddComponent(typeof(MeshRenderer)) as MeshRenderer;
 renderer.material.mainTexture    =     staticTex;

This works fine on the editor, but i get a pink texture on the iPhone. Im using: Unity : 5.5.0f3 Xcode : 8.0 iOS : 10.0.2

This used to work as expected in previous builds but has just stopped working now.

I have tried:

  1. Clearing the GI cache

  2. Making sure shaders are included by adding a test shader.

Not sure what is going wrong, or what has changed. Any help is appreciated!

Update: The behavior is the same on an android device as well. Just tested with a galaxy s7!

Comment
interpol_kun

People who like this

1 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 herDev · Feb 15, 2017 at 12:15 PM 0
Share

Hi, I've ran into a similar problem before (pink textures on device) and it related to the compression settings for the texture. Hope that helps!

avatar image GambitDev herDev · Feb 15, 2017 at 12:34 PM 0
Share

@herDev, thanks for the reply! What is the recommended compression setting for android and iOS?

3 Replies

· Add your reply
  • Sort: 
avatar image

Answer by GambitDev · Feb 19, 2017 at 10:56 PM

After a few days of trying things i finally got the solution to this. It was an issue with unity not finding/compiling the shader for any of the builds. I just had to add a dummy material in my "Resources" folder (doesnt need to be used) and unity picks this up and compiles the shader for the build.

This happened as a result of me re-organizing the folder structure in my project. I organized all my scripts, assets in my unity project and created a "Resources" folder where i add textures and Prefabs. At this point i had no materials here as all my materials were being created and added at run time. Somehow unity considered this is the project not utilizing any materials and that it was not required to compile any shader.

Adding a dummy shader in my "Resources" folder fixed this issue. Now everything works as expected.

This link http://answers.unity3d.com/questions/1147277/textures-from-local-works-in-editor-missing-in-bui.html gave me the solution for my problem. Hope this helps anyone in the future facing the same issue.

Comment
TSantosFigueira
ralfderijcke
interpol_kun
Idlerid

People who like this

4 Show 2 · 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 interpol_kun · Mar 20, 2018 at 03:17 PM 0
Share

Had the same issue. But I was creating material by Shader.Find and it appeared not working because I deleted some om UNUSED materials from project folder.

Your solution works good. Now I am creating a material instance directly from resource folder.

avatar image Idlerid · Sep 05, 2018 at 03:42 AM 0
Share

I just transferred all my materials to "Resources" folder and in worked for me, thanks!

avatar image

Answer by danilocjr · Mar 23, 2020 at 04:32 AM

A simple way to do this is:

  1. Go to >> Project Settings >> Graphics >> Always Included Shaders

  2. Add 1 in size (to add another element)

  3. Select the Shader you're going to or using it

This way you're going to compile all needed shaders for your build. Don't forget to select the correct platform (iOS/Android/Standalone)

Comment
nitz

People who like this

1 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 nitz · Nov 18, 2021 at 12:47 PM 0
Share

This, as well as the other answers, worked for me. I feel like this is the 'cleanest' approach to the problem.

avatar image

Answer by himichelleng · Apr 10, 2018 at 04:58 AM

Thank you for giving me a clue to solve a similar problem. In my case, I was trying to add a Video Player component to a plane programmatically, and the video would work in editor and not in the iOS build. Tried both adding dummy shader and dummy material into the Resources folder and it wouldn't work.

So what I did was to create a dummy plane (with transform scale as 0 and position behind the camera) that has the Video Player component with a video attached. Problem solved!

Comment

People who like this

0 Show 0 · 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

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

10 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

Related Questions

Forge Networking Remastered iOS Build Error 1 Answer

VR Viewport shrunk toward bottom of screen on iPhoneX 0 Answers

How to save textures to iOS devices, ask for help. 1 Answer

IL2CPP error on Unity5 1 Answer

My iPhone Builds with Unity 5.1 and up on iPhone 4 and 5c are having issues 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges