Search Unity

[url]WWW.error[/url] confusion

Discussion in 'Scripting' started by ratamorph, Apr 24, 2008.

  1. ratamorph

    ratamorph

    Joined:
    Sep 2, 2007
    Posts:
    458
    I'm trying to load a remote image for a texture but in case the URL is not correct, no internet conection, etc, I want to use a local backup texture.

    He's the code I'm using to acomplish this, the problem is that if the image url is correct but it's not a jpg or a png the error seems to stay at null and I get the red question mark.

    Code (csharp):
    1.  
    2. remoteTexture = new WWW(remoteTextureURL);
    3. yield remoteTexture;
    4.    
    5.    
    6. if(remoteTexture.error)
    7. {
    8.    useRemoteTexture = false;
    9.    finalTexture = texture;
    10. }
    11. else
    12. {
    13.    useRemoteTexture = true;
    14.    finalTexture = remoteTexture.texture;
    15. }
    16.  
    How do I change this in order to use the backup texture in this case?
     
  2. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    The only way I've found to handle this is something like

    Code (csharp):
    1. if (remoteTexture.error || (remoteTexture.texture.width == 8  remoteTexture.texture.height == 8)) {
    Since the question mark thingy is a 8x8 texture. Granted, this is a hack (what if you really want to use a valid 8x8 texture for some reason, or what if UT changes the size of the question mark?), so hopefully someone has a better idea....

    --Eric
     
  3. ratamorph

    ratamorph

    Joined:
    Sep 2, 2007
    Posts:
    458
    Thanks Eric, that's quite a hack but it works for me now, I hope they change WWW.error so it reports non supported image formats as errors.
     
  4. Marc

    Marc

    Joined:
    Oct 4, 2007
    Posts:
    499
    I use kinda the same hack and its really ugly simply put it means that one cant use 8x8 textures. I have made a feature request to UT that the function be made to return null instead of the texture. Sometimes making things "Just work" is taking the error auto fixing to far. I do belive that the developers who makes the download textures script should handle what happens if they get a 404 error and not unity, although admittedly it is convenient sometimes to see the question mark, but i would much rather code it my self and have a null value instead.