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

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

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.