x


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

more ▼

asked Jul 12 '11 at 10:56 AM

Sixakoo_ gravatar image

Sixakoo_
100 7 9 10

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);
 }
Sep 09 '11 at 04:28 AM MattMaker

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

Sep 09 '11 at 11:47 AM Waz

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.

Sep 09 '11 at 10:44 PM MattMaker

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.

Sep 09 '11 at 10:46 PM MattMaker
(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

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

more ▼

answered Jul 12 '11 at 12:06 PM

Waz gravatar image

Waz
6.4k 22 33 71

(comments are locked)
10|3000 characters needed characters left

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://www.unifycommunity.com/wiki/index.php?title=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.

more ▼

answered Sep 30 '11 at 06:42 PM

MattMaker gravatar image

MattMaker
71 1 3

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

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

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x2199
x525
x380
x52
x9

asked: Jul 12 '11 at 10:56 AM

Seen: 1493 times

Last Updated: Sep 30 '11 at 06:42 PM