Loading images(dynamically) from server that blocks UI thread

My app loading images from server and assigns to UI.Image by converting the download texture to sprite using the following code

Sprite sprite = Sprite.Create(mTexture, new Rect(0, 0, mTexture.width, mTexture.height), new Vector2(0.5f, 0.5f), 100, 0, SpriteMeshType.FullRect);

Images are loaded and displayed properly, but the app gets block or hangs(means some noticeable period less than a second) until image gets load. Also the entire images in a recyclable list. When I try to swipe and move to the next item, app will load new set of images and its affect the smooth swipe experience and gives feel like shutter.

Can anyone suggest your ideas to resolve this issue and to make the swipe smooth?

How big are the images? Also may help to see how you have your image downloading and creation setup.

Not without actually knowing what you are doing and seeing some code. For starters you havent even detailed or shown how you download the images, you just say “downloading images”

AssetBundles and addressable assets supports async sprite loading, hope this will help. Otherwise there’s no API to create sprite without blocking main thread for the time of creation because Sprite.Create may be called from the main thread only.

1 Like