• 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 Sixakoo_ · Jul 12, 2011 at 10:56 AM · texturewwwchangereplaceloadimageintotexture

Is there a way to replace the question mark in the WWW.LoadImageIntoTexture?

According to the Unity Script Reference WWW.LoadImageIntoTexture page, "if the data is not a valid image, the generated texture will be a small image of a question mark." Is there any way to change the question mark or at least get a return from the error, so that I could replace the texture manually? Thank You.

-Sixakoo

Comment
Paulius-Liekis
tarasfromlviv
callen

People who like this

1 Show 4
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 MattMaker · Sep 09, 2011 at 04:28 AM 1
Share

Possibly:

      public static bool isErrorImage(Texture tex) {
       //The "?" image that Unity returns for an invalid www.texture has these consistent properties:
       //(we also reject null.)
       return (tex && tex.name == "" && tex.height == 8 && tex.width == 8 && tex.filterMode == FilterMode.Bilinear && tex.anisoLevel == 1 && tex.wrapMode == TextureWrapMode.Repeat && tex.mipMapBias == 0);
  }
avatar image Waz · Sep 09, 2011 at 11:47 AM 0
Share

I suspect, since a PNG can't specify anisoLevel etc anyway, this may reject any every 8x8 image, unless .name alone is useful.

avatar image MattMaker · Sep 09, 2011 at 10:44 PM 0
Share

You are correct: http://dummyimage.com/8x8/f00/fff.png is falsely identified as the "?" by this test. And Bilinear,1,Repeat,0 are simply the default values for Texture, so they are redundant here.

avatar image MattMaker · Sep 09, 2011 at 10:46 PM 0
Share

However, it's entirely possible (even probable) that a particular project can be guaranteed to never intentionally require a WWW download of an 8x8 image. In that case, this function is sufficient.

2 Replies

· Add your reply
  • Sort: 
avatar image
Best Answer

Answer by Waz · Jul 12, 2011 at 12:06 PM

No. The most you can do is check the image against a known-failed image (like file://nosuchimage).

Comment
sneftel
Sixakoo_
MattMaker
Paulius-Liekis
Loius

People who like this

5 Show 3 · 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 emathew · Oct 10, 2017 at 08:13 PM 0
Share

Could you show us code that resembles what you are talking about?

avatar image Bunny83 emathew · Oct 10, 2017 at 09:39 PM 1
Share

He just suggests that you first use the WWW class to try to load any file path where you know it doesn't exist. That means as result you get the "questionmark" texture. You save it for reference in a variable. When you actually loading your images you can compare the result with the reference texture.

avatar image emathew Bunny83 · Dec 11, 2017 at 02:38 PM 0
Share

Thank you, that is much clearer!

avatar image

Answer by MattMaker · Sep 30, 2011 at 06:42 PM

Warwick Allison's suggestion (of comparing to a "known-failed" image) is probably the best, most future-proof option. Another possibility which is a little simpler, but will fail if unity ever changes the appearance of the default "error" texture, is to convert your texture into an array of bytes using EncodeToPNG(), and compare the array to a predetermined array representing the PNG-encoded version of the default "error" texture.

I have implemented an example of Warwick Allison's suggestion, plus the other technique I suggest, here: http://wiki.unity3d.com/index.php/TextureBogusExtensions

I implemented it as a C# extension method on the Texture class, which may be overkill. But people keep asking this question on the #unity3d IRC chat channel, so I figured I'd put the code out there.

Comment

People who like this

0 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 emathew · Oct 10, 2017 at 08:12 PM 0
Share

The link does not load... Could you forward us to the valid URL

avatar image Bunny83 emathew · Oct 10, 2017 at 09:59 PM 0
Share

I've fixed the old wiki link. However, at least on my side, the wiki currently seems to be unreachable. I get a "Bad Gateway" after some time.

Though i found the same script on a random Github repository

avatar image emathew Bunny83 · Dec 28, 2017 at 06:25 PM 0
Share

Hey, I've tried implementing this solution, but it seems like it is very computationally expensive (my framerate drops like 50%). Also, since my texture is jpg, my app is still rendering dropped frames which result in the red question mark. Do you have any other ideas on how I could get past this issue?

avatar image Bonfire-Boy · Dec 29, 2017 at 04:18 PM 0
Share

"will fail if unity ever changes the appearance of the default 'error' texture"

But the texture must be in the build, surely? So it'll only fail if one neglects to update the byte array when that texture changes.

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

7 People are following this question.

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

Related Questions

Glitch when using WWW.LoadImageIntoTexture(...) 2 Answers

Loading Images using WWW into a different texture format 2 Answers

LoadImageIntoTexture Runtime Change 1 Answer

Image loaded with LoadImageIntoTexture gets inverted 0 Answers

LoadImageIntoTexture on iPhone from the device disk 1 Answer


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