Search Unity

Loading images(dynamically) from server that blocks UI thread

Discussion in 'Scripting' started by azad_shekmydeen, Sep 20, 2019.

  1. azad_shekmydeen

    azad_shekmydeen

    Joined:
    Jun 18, 2014
    Posts:
    1
    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?
     
    Last edited: Sep 20, 2019
  2. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    7,187
    How big are the images? Also may help to see how you have your image downloading and creation setup.
     
  3. MadeFromPolygons

    MadeFromPolygons

    Joined:
    Oct 5, 2013
    Posts:
    3,980
    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"
     
  4. palex-nx

    palex-nx

    Joined:
    Jul 23, 2018
    Posts:
    1,748
    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.
     
    doctorpangloss likes this.