Search Unity

Texture loaded using UnityWebRequest shows up as red questionmark

Discussion in 'Scripting' started by Roywise, Oct 16, 2019.

  1. Roywise

    Roywise

    Joined:
    Jun 1, 2017
    Posts:
    68
    In our project we download almost all our assets during runtime using UnityWebRequests. We recently noticed that one specific image shows up as a red question-mark.

    Usually a red question-mark would mean that the asset could not be found or something went wrong during the download but in this case the path is correct and we didn't receive any network error, we verified it by using Postman and visiting the URL in a browser.

    We expect the image to contain some data that Unity can't process and we've been looking into what makes this image different from all the other assets but haven't found the exact cause yet.

    Weirdly enough the image works without any issues when it is dragged into the Unity Editor. I expected Unity to handle downloaded assets the same way as it would when imported into the project.


    I created a project that reproduces the issue, it contains a Unity project with some code to load an image from the StreamingAssets folder using a UnityWebRequest during runtime. It also contains two images that I can reproduce the issue with.

    For people that are interested, you can download the reproduction project here.


    Who has encountered this issue before? Any suggestions?
     
  2. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,736
    The red questionmark indicates that texture could not be created from downloaded bytes.
    Does the error happen in Editor? Is there any error in the console?
    Try reading file using File class and create texture using ImageConversion class.
     
  3. nilsdr

    nilsdr

    Joined:
    Oct 24, 2017
    Posts:
    374
  4. Roywise

    Roywise

    Joined:
    Jun 1, 2017
    Posts:
    68
    @Aurimas-Cernius

    It happens in the Editor, but not when you drag the images into the Editor. (In that case they're not loaded using a UnityWebRequest.) There are no error or warning messages in the Editor at all.

    Using File.ReadAllBytes to read the file and using ImageConversion.LoadImage to create the Texture2D, the result is the same red questionmark.

    @nilsdr Thanks, I'll take a look at the link you've posted.
     
  5. Roywise

    Roywise

    Joined:
    Jun 1, 2017
    Posts:
    68
    The issue is clear after doing some extra research on the things @nilsdr mentioned. I still think it is strange that Unity handles it without issues when the images are dragged into the Editor.

    We'll have to start looking into ways to convert a byte array into valid CMYK data and convert that to RGB. Then we should be able to create the texture. Hopefully.
     
  6. nilsdr

    nilsdr

    Joined:
    Oct 24, 2017
    Posts:
    374
    Far from an expert on this but isn't CMYK used for print mostly? Wouldn't it make sense to just store the textures for the app in RGB?
     
  7. Roywise

    Roywise

    Joined:
    Jun 1, 2017
    Posts:
    68
    @nilsdr
    As I understood from reading about it on the internet CMYK is mostly used for printing purposes, yes.

    Storing all textures for the app in RGB would be the best solution but not feasible for our project.

    1. Users can upload their own images to use within the software.
    2. Users can select images from an image-websearch.
    3. We have to keep in mind legacy saved data from previous versions of the software in which it did load those images.

    So we don't have full control over what the user does and we need to support data that the user already saved. Especially that last one is important to us.
     
  8. nilsdr

    nilsdr

    Joined:
    Oct 24, 2017
    Posts:
    374
    Thats understandable. For what it's worth, perhaps that image conversion is probably easier to do in whatever api / upload script you have than it is to do it client side. Also i'd imagine there would be a performance penalty.
     
  9. Roywise

    Roywise

    Joined:
    Jun 1, 2017
    Posts:
    68
    @nilsdr
    Thanks for the suggestion. We're discussing the possibility to do the conversion in our backend.
     
  10. Roywise

    Roywise

    Joined:
    Jun 1, 2017
    Posts:
    68
  11. MadeFromPolygons

    MadeFromPolygons

    Joined:
    Oct 5, 2013
    Posts:
    3,983
    Has anyone figured out a way to download a texture via webrequest when it is failing like this?

    Really need to convert these images to work
     
  12. jsr2k1

    jsr2k1

    Joined:
    Aug 11, 2010
    Posts:
    118
    Hello, this problem persists with Unity 2022.2.5 but is worst because it crashes the web browser.
    In the chrome console, the error is 'unsupported color conversion request'.

    The same set of images worked properly with Unity 2020.3.34
    Is there any change from 2020 to 2022 causing this issue?

    Any idea how to fix this problem?