Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • 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
0
Question by Valdameer · Feb 01, 2013 at 05:18 AM · texture2dwww

Any way to validate WWW.texture

When using WWW.texture, if the WWW request was unable to get parse the response data into a Texture2D then it returns a "dummy link"

The data must be an image in JPG or PNG format. If the data is not a valid image, the generated texture will be a small image of a question mark

Does anyone know of way to validate that what is returned is NOT that dummy question mark?

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 gfvfubb · Feb 01, 2013 at 05:47 AM 0
Share

I'm not sure what form the data is in, but if you can get it in an object where you can check the .width / or .height like in Texture base class that would work.

avatar image Valdameer · Feb 01, 2013 at 06:12 AM 0
Share

The question mark image is 8x8, I could check against it, but that imposes a limitiation on the web service that it isnt allowed to host images that are 8x8 lest they be filtered by the application

5 Replies

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

Answer by Danmietz · Feb 01, 2013 at 08:15 AM

A similar question has been asked previously; Warwick Allison gave the following answer;

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

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 Valdameer · Feb 05, 2013 at 11:35 PM 0
Share

Damn, that is the worst.

avatar image
0

Answer by Bunny83 · Feb 06, 2013 at 12:01 AM

How about using Texture2D.LoadImage? It returns a boolean. The documentation doesn't say anything about it, but i guess it will tell you success / failure of the function.

Comment
Add comment · 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 Valdameer · Feb 06, 2013 at 01:01 AM 0
Share

Interesting, Texture2D forces you to specify height and width at instantiation, but the documentation says LoadImage can override it. This could work much better. I'll take a look.

avatar image Valdameer · Feb 06, 2013 at 01:28 AM 0
Share

Nope, has the exact same behaviour. Returns true with the 8x8 image when given crummy data.

avatar image Bunny83 · Feb 06, 2013 at 10:09 AM 0
Share

Hmm, well if it does you can use it to produce the bogus texture more efficiently than loading a WWW page ;). That means you can use LoadImage with bogus data in this extension. That would completely remove the need for a coroutine.

avatar image
0

Answer by standardcombo · Feb 04, 2015 at 07:01 PM

I was looking for a solution to this and have found that checking the size does the trick.

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
avatar image
0

Answer by Zocker1996 · Feb 09, 2015 at 01:59 PM

You can start this in a Coroutine:

 private IEnumerator LoadImages (string path, UnityAction<Texture2D> textureCallback)
 {
     WWW www = new WWW (path);
     yield return www;
     if (www.error != null) {
         //there was an error
         textureCallback.Invoke(null);
     } else if (www.texture.width == 8 && www.texture.height == 8) { 
         //there seems to be an unsupportet file or the user really passed a 8 x 8 image.    
         textureCallback.Invoke(null);                    
     } else {
         //all fine
         textureCallback.Invoke(www.texture);                        
     }
 }
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
avatar image
0

Answer by HeyNau · May 05, 2019 at 10:30 AM

I've just checked that those error images have 8x8 size. So if you work with higher res images you can check them with something like this:

 bool CheckIfImageExists(Texture imageToCheck) {
    return imageToCheck.width > 10 && imageToCheck.height > 10;
 }





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.

Follow this Question

Answers Answers and Comments

16 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 avatar image avatar image avatar image

Related Questions

LoadImageIntoTexture function on webplayer 0 Answers

Smooth Synchronized HD Video Playback 0 Answers

Displaying an image from a resource folder. 2 Answers

What is the best way to persist www downloaded graphics? 1 Answer

Unity won't let me load an image into a texture 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