Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question Mark Texture

Discussion in 'Scripting' started by Downie, Jan 26, 2010.

  1. Downie

    Downie

    Joined:
    Nov 2, 2009
    Posts:
    23
    I am attempting to load a file from a folder into Unity at runtime using the WWW class. The problem is I always get the dreaded question mark texture but I don't know why.

    I yield on the WWW class and log any errors (none appear, unless I change the path then I get a correct error about not finding the file). I even check isDone before assigning the texture; but still get the question mark. My texture is a png.

    Does anyone have any ideas?

    Thanks

    Code (csharp):
    1.  
    2. function LoadTextureFromFile(FileName : String)
    3. {
    4.     var download : WWW = new WWW(FileName);
    5.     yield download;
    6.    
    7.     if(download.error)
    8.     {
    9.         print(download.error);
    10.         download  = null;
    11.     }
    12.     else if(download.isDone)
    13.     {
    14.         myTexture2D = download.texture;
    15.         download  = null;
    16.     }  
    17.     else
    18.     {
    19.         Debug.Log("Couldnt load resource");
    20.         download  = null;
    21.     }  
    22.  
    23. }
    24.  
     
  2. andeeeee

    andeeeee

    Joined:
    Jul 19, 2005
    Posts:
    8,768
    Is it possible the PNG file is corrupt or invalid in some way? The download might complete successfully, but the data could still be incorrect.
     
  3. Downie

    Downie

    Joined:
    Nov 2, 2009
    Posts:
    23
    Well it is difficult to check if the png is corrupt when downloaded onto the device (it may be corrupted in the progress); but the source png is fine. As for invalid? That's really what I am wondering about. In what other way can it be invalid?

    Thanks
     
  4. andeeeee

    andeeeee

    Joined:
    Jul 19, 2005
    Posts:
    8,768
    A PNG file could conceivably have valid checksums, but contain incorrect or inconsistent data. I think some apps make a sterner attempt than other to cope with incorrect data, so I guess a file may display in some apps, but not Unity. Have you tried the download with any other PNG files and found they work OK?
     
  5. AaronC

    AaronC

    Joined:
    Mar 6, 2006
    Posts:
    3,552
    Is there a way to just kill that questionmark? I have it temporarily, and then a good texture updates over it but the red questionmark just ruins it for up to a second. A black one would be ideal. Is there any way to get to that and substitute it? Is it inside Unity or fetched from the web?

    Cheers
    AC
     
  6. rohKan

    rohKan

    Joined:
    Sep 24, 2012
    Posts:
    8
    Anybody found a solution to this problem yet? I am facing this problem on mobile devices i.e ios and android :(
     
  7. Juang3d

    Juang3d

    Joined:
    Sep 25, 2012
    Posts:
    87
    I have this problem and it is random, the PNG files are perfectly fine, there are times when they are correctly downloaded and there are times when the WWW returns an OK to the download but what I get is that red question mark, and it is random.

    Why is this happening? It's like there are times when the WWW is not returning an error even when it failed.

    Cheers.
     
  8. Juang3d

    Juang3d

    Joined:
    Sep 25, 2012
    Posts:
    87
    There are times when I get also this:

    "
    You are trying to load data from a www stream which had the following error when downloading.
    503 Service Temporarily Unavailable
    UnityEngine.WWW:get_texture()
    "

    But the WWW did not return any error, this message appears when I try to access the texture.

    Cheers.
     
  9. emathew

    emathew

    Joined:
    Jul 31, 2017
    Posts:
    13
    Would be great to get an update on this if anyone has one!
     
  10. emathew

    emathew

    Joined:
    Jul 31, 2017
    Posts:
    13
    Where you able to find a way to bypass/kill the question mark?
     
  11. schreibtischkrieger2019

    schreibtischkrieger2019

    Joined:
    Jul 12, 2019
    Posts:
    13
    i face nearly the same problem. I try to do an app like Whatsapp. When i post an image it is sent to the server. Then the app downloads it from the server again. Then my app updates the chat and tries to display the new image(With a webrequest using "file//......path....". Very often i get this questionmark or even a grey texture. If I reopen the chat again then the image is always placed correctly.

    What i believe is, that the file exists on the disk, but is still streaming the data. Later the file is fine.
    I tried to check if the file isLocked ( U can find a weird solution for this, not sure if its correct) but it didnt help.

    I struggle here a little.... if someone finds a solution after 11 years... it would be nice :)
     
  12. AaronC

    AaronC

    Joined:
    Mar 6, 2006
    Posts:
    3,552
    Try storing a substitute file locally in your app, leave it as placeholder until desired pic has fully downloaded, maybe yield a frame then apply?
     
  13. schreibtischkrieger2019

    schreibtischkrieger2019

    Joined:
    Jul 12, 2019
    Posts:
    13
    if i post the pic and first use the local file would work i guess.. but its not the right solution. If someone receives the pic then he doesnt have the local file... he would first see the questionmark and if he opens the chat again, then he would see the correct image..... not useable..
    There seems not to be anything like an event that a file is fully downloaded..
     
  14. AaronC

    AaronC

    Joined:
    Mar 6, 2006
    Posts:
    3,552
    I mean embedded in your app. Like a little " loading" icon or something, to ease the transition
     
  15. schreibtischkrieger2019

    schreibtischkrieger2019

    Joined:
    Jul 12, 2019
    Posts:
    13
    oh, ok. I use a placeholder icon(later buffering animation) In the backround, there runs a coroutine that tries to get the real image, from disk. But when the webrequest returns a texture it stops. But its often a grey texture or a questionmark
     
  16. schreibtischkrieger2019

    schreibtischkrieger2019

    Joined:
    Jul 12, 2019
    Posts:
    13
    here is my coroutine. it checks if File.exists... but it seems that existing is not the same as fully downloaded an saved..

    Code (CSharp):
    1.  IEnumerator LoadImage()
    2.         {
    3.             bool imgLoaded = false;
    4.  
    5.             while (!imgLoaded)
    6.             {
    7.                 var filePath = FilePool.GetFinalFilePath(_extension);
    8.                 var fileInfo = new FileInfo(filePath);
    9.                 var fileIsLocked = FileUtilities.IsFileLocked(fileInfo);
    10.                 var fileAge = FileUtilities.GetFileAgeInSeconds(fileInfo);
    11.  
    12.                 if(File.Exists(filePath) && !fileIsLocked)
    13.                 {
    14.                     UnityWebRequest www = UnityWebRequestTexture.GetTexture("file://" + filePath );
    15.                     yield return www.SendWebRequest();
    16.                     try
    17.                     {
    18.                         //SpriteImage.sprite = GetThumbnail(_extension);
    19.  
    20.                         Texture2D myTexture = null;
    21.  
    22.                         if (www.isNetworkError || www.isHttpError)
    23.                         {
    24.                             throw new Exception(www.error);
    25.  
    26.                         }
    27.                         else
    28.                         {
    29.                             myTexture = ((DownloadHandlerTexture)www.downloadHandler).texture;
    30.                             RawImage.texture = myTexture;
    31.                             imgLoaded = true;
    32.                         }
    33.                     }
    34.                     catch (Exception exception)
    35.                     {
    36.                         //nothing
    37.                         Debug.LogError(exception);
    38.                     }
    39.                 }
    40.  
    41.                 yield return new WaitForSeconds(1);
    42.             }
    43.  
    44.             yield return 0;
    45.         }
     
  17. schreibtischkrieger2019

    schreibtischkrieger2019

    Joined:
    Jul 12, 2019
    Posts:
    13
    maybe i should add that the problems only occur on mobile platform(android)
     
  18. schreibtischkrieger2019

    schreibtischkrieger2019

    Joined:
    Jul 12, 2019
    Posts:
    13
    when i add a counter and let it load the texture 4 times, then i get 4 different textures: the first is gray, the second has the top area with the real image but the majority of the image is gray. The 3rd has a little more of the real image... and so on...

    So it is really like the file is streaming slowly in the background so i need an event or a property that tells me if the file is fully downloaded...

    maybe i can store information about the size of the file in the database and wait until the file has the size?
     
  19. schreibtischkrieger2019

    schreibtischkrieger2019

    Joined:
    Jul 12, 2019
    Posts:
    13
  20. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,637
    The question mark is default image that you get when downloaded data is not an image (or is corrupted).
    On Android you have to be careful on how you read files, since files on disk can be accessed via C# file APIs, but files inside apk cannot (persistentDataPath, dataPath, streamingAssetsPath). UnityWebRequest can read files from inside apk, but make sure you don't corrupt them since they are jar:file:// URIs and should remain such.
    Also, make sure to check for error when downloading, in particular, if you get an isHttpError, the the downloaded data is most likely not an image.
     
  21. unnanego

    unnanego

    Joined:
    May 8, 2018
    Posts:
    188
    I have this problem with latest unity, also randomly, and it happens both in editor and on builds. And the thing is, the textures are fine, if I load the texture again from storage it gets loaded ok and I check the downloaded files manually - everything works fine.

    Is there a way to check if the texture didn't load and try to reload it?
     
  22. schreibtischkrieger2019

    schreibtischkrieger2019

    Joined:
    Jul 12, 2019
    Posts:
    13
    Hello, in my case i store the filepath in a list, then download it. After the download i remove it from the list.
    In the background i have a textureRequestEngine that checks if the name is still in the list. If its not in the list anymore it reads the texture with webrequest. I kind of solved it but dont know if its the best way.
    Sry for late answer.
     
  23. unnanego

    unnanego

    Joined:
    May 8, 2018
    Posts:
    188
    oh, I rewrote everything with async await and now everything works, but I'm not sure that it's what helped...
     
  24. nsmith1024

    nsmith1024

    Joined:
    Mar 18, 2014
    Posts:
    869
    Anybody solved this problem? Im having it too, it appears as a red question mark instead of the actual image. The image at the URL is perfectly fine. The same function loads other images from other urls and it works, very strange!

    I dont know how to fix it, any ideas?
     
  25. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,637
    Can you give a link to that image?
     
  26. stilkin

    stilkin

    Joined:
    Jan 6, 2021
    Posts:
    4
    I don't know if this helps anyone, but I have gotten the question mark texture when loading .heic files in the Unity Editor (they work just fine on iOS and Android). So in my case it was an incompatible file type...
     
  27. unity_yjSL7Cwu47x7cg

    unity_yjSL7Cwu47x7cg

    Joined:
    Apr 29, 2022
    Posts:
    1
  28. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,719
    Both of those files are corrupt to Gimp.

    Screen Shot 2022-05-12 at 9.42.29 PM.png
     
  29. Bunny83

    Bunny83

    Joined:
    Oct 18, 2010
    Posts:
    3,526
    The second one is not a png but a WebP file. When I download and save the file locally with FireFox, it actually gets the extension "webp". Opening the file in a n Hex editor shows this:
    upload_2022-5-13_8-8-7.png

    So it's a RIFF container that contains a WEBPVP8 image. So it's not a png file. The URL may have named it png, but that doesn't make it a png ^^. Writing the letters "CAT" onto a dog with paint won't turn the dog into a cat :)
     
    MelvMay likes this.
  30. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,719
    Some help to fix "Cannot implicitly convert type 'Dog' into 'CAT':"

    http://plbm.com/?p=263

    (Sorry Bunny, couldn't resist... :) )
     
  31. donat_01

    donat_01

    Joined:
    Aug 1, 2020
    Posts:
    4
    verify link, this ends with .pgn, if not, changue the ends of link. example:
    .replace(".webp", ".png")