- Home /
Issue with downloading textures in 2021.1.13 using unitywebreques
prior to using 2021.1.13 I was able to download a texture from a url using the following code
UnityWebRequest www = UnityWebRequestTexture.GetTexture(url, true);
yield return www.SendWebRequest();
Texture2D tex=((DownloadHandlerTexture)www.downloadHandler).texture;
and access the image raw data using
byte[] data=((DownloadHandlerTexture)www.downloadHandler).data;
As I need access to both the image as a texture, and as a raw byte array.
However, in 2021.1.13 data always comes back null. Is this a bug, or expected behaviour now?
I have discovered a workaround using the following code
UnityWebRequest www = new UnityWebRequest(url);
var downloadHandlerBuffer = new DownloadHandlerBuffer();
www.downloadHandler = downloadHandlerBuffer;
yield return www.SendWebRequest();
Texture2D tex = new Texture2D(2, 2);
byte[] data = downloadHandlerBuffer.data;
ImageConversion.LoadImage(tex, data, true);
Is this now the correct way to do this loading process?
Answer by MaskedMouse · Sep 01, 2021 at 09:17 AM
If things work prior to another version, it's definitely a bug. I've stubled upon this as well. We usually use DownloadHandlerFile to cache the file. Then another request to the cache to download the actual texture. That seems to bypass it as well. But when the file isn't cached it'll cache it while getting the texture from web. Thus also uses the downloadHandler.data property which now suddenly returns null.
I've reported the bug to Unity.
Your answer
![](https://koobas.hobune.stream/wayback/20220613035841im_/https://answers.unity.com/themes/thub/images/avi.jpg)