0

Here it is my code: https://pastebin.com/n4dQf7WW

Basically my problem is the fact that I download something like 10/15 images in one time to fill my homepage. But generating all these images will freeze the app on both iOS and Android.

More facts: - On iOS the download won't start immediately, on Android does. - I used the UnityWebRequest functions, but on iOS it won't work concurrently. - On Android it works as it should be, but when it comes to create the Sprite/Texture it freezes until it's finished.

So what I'm asking is if there is a way to handle better this situation (even with third-party library both paid and free).

I think the problem is here on the WebClient_DownloadDataCompleted function:

 var texture = new Texture2D(2, 2);
        texture.LoadImage(imageBytes);
        Rect rec = new Rect(0, 0, texture.width, texture.height);
        var spriteToUse = Sprite.Create(texture, rec, new Vector2(0.5f, 0.5f), 100);
Roberto Pelonara
  • 21
  • 1
  • 1
  • 8
  • `Texture2D.LoadImage` is very expensive function and it should be run on Unity mainthread. As I know, there is no perfect way for this issue, but there are some options like to use native plugin or `Texture2D.LoadRawTextureData`, etc. However, I think there is no way to satisfy you. But you can refer to this https://stackoverflow.com/questions/40450867/non-blocking-loading-and-copying-of-large-texture2ds-in-c-sharp-for-unity – Heejae Kim Feb 21 '19 at 13:09
  • To prevent freeze you need to download your images asyncronous. – joreldraw Feb 21 '19 at 13:42

0 Answers0