Search Unity

Asset Bundles optimize loading time

Discussion in 'Asset Bundles' started by PopsawayGames, Mar 30, 2020.

  1. PopsawayGames

    PopsawayGames

    Joined:
    Jan 2, 2018
    Posts:
    25
    Hey all,
    We're developing a game app for Android and we use Asset Bundles downloaded from server to load assets runtime. We're very deep in development, so our total app size is like 1.5/2 GB ( apk is 90 MB and the rest is in bundles ).
    I use LoadFromFile() and then LoadAssetAsync() to load bundles and assets.
    All bundles are uncompressed.
    We're using Unity 2018.3.14f1.

    The problem is that loading takes up a lot of time ( min like 5-6 seconds ). For example, I have a scene with characters team, the classic team selection with all players unlocked characters. Every char have an animation that is essentially a "Dragonball like" aura, made simply with a sequence of .png sprites 554x554. That animation is loaded from AssetBundle (it's 130 MB), and I have currently 6 characters that need their animation loaded at scene start (each with ). Profiling, most time is used to load bundles, so I know the problem is that.

    I'm using a coroutine that starts in Awake(), instantiates a loading screen and loads asynchronously each animation, so work is splitted correctly between frames. Then, when loading is completed, loading screen is disabled and everything is displayed fine.

    Is this the best way to load bundles? I read in the Unity Manual that the fastest way to load bundles is LoadFromFile(), but it freezes because is synchronous, and the speed gained is not so much. I also read that there is a caching system and I have server I can download bundles from using UWR, so I could easily cache them. I can't test caching right now because of time problems, so I will use it only if it is really faster.

    I see everyday games made with Unity that loads resources very very fast with 3D models and big world scenes, I only have a 2D game with no complex stuff, just some animations that are a bit heavy ( from 50 MB to 200 MB more or less). From inspecting these games folders with device folders browser, if I'm right, I did not see a caching and resources organization system totally different from mine so... Is that some magic I am missing? could it be a plug-in or a handmade loading script?

    So my questions are:

    1) Is AB Caching recommended and does it speed up loading that much?

    2) Since AB are uncompressed, they won't be loaded in memory but only the header, so the focus is a faster AB loading or a faster ASSET loading? from my tests I don't find a good answer

    3) As I mentioned, there are a lot of games made with Unity ( big ones like Dragon Ball Legends, Digimon ReArise, Kings Raid, Seven Deadly Sins Grand Cross, Crossing Void, Gears Pop...and the list is endless ),
    they load resources extremely fast, and the apk size is like 50 MB, and there is a downloading files when app start so they obviously use AB or a similar system. Then how is that possible?

    4) Could addressable system be better/faster? ( I only care about performance and loading speed, complexity is not a problem )

    5) Could splitting apk and obb be a solution? downloading apk from Google Play and then downloading obb file with everything inside, in first scene after a new player login?

    6) Do you have any advice for me? any adviced plug-in or handmade method to load bundles fast?

    If I forgot some info I will edit as soon as I can for you better understanding.
    Thanks a lot to everyone!!!
     
    CBHM likes this.
  2. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,736
    There is also LoadFromFileAsync().
    The purpose of caching is for downloading bundles from the internet. In such case you can download compressed bundles to save the bandwidth, they are recompressed to cache for more efficient load in the future. I don't thing there is a difference between loading from cache and loading from (uncompressed) file.
    OBB versus bundles download is tricky. The advantage of individual bundle download is that you can download the ones that you need, while the remaining one can be downloaded on demand or in background. With OBB you have all at hand and don't have to worry about things like app data erasure etc.
     
  3. PopsawayGames

    PopsawayGames

    Joined:
    Jan 2, 2018
    Posts:
    25
    Hi Aurimas! thanks for reply
    Ok, so caching bundles doen't look like the solution for me unfortunately...and the OBB problem you mentioned is exactly what I was thinking...maybe addressables could load faster? It's for sure something I'm missing on loading optimization :confused:
     
  4. PopsawayGames

    PopsawayGames

    Joined:
    Jan 2, 2018
    Posts:
    25
    Daily bump!
     
  5. Neto_Kokku

    Neto_Kokku

    Joined:
    Feb 15, 2018
    Posts:
    1,751
    Since I don't know how your project is structured, here are some general things you can try:

    - Test using chunk compression on your bundles. It will reduce the time transferring data from the phone storage to memory.
    - It sounds like you're loading one animation at a time in a coroutine. You could try starting several async load operations at once to maximize disk access.
     
  6. PopsawayGames

    PopsawayGames

    Joined:
    Jan 2, 2018
    Posts:
    25
    Nice!
    I thought ( and I was wrong ) that every compression slowed down loading time regardless of compression type. I read how LZ4 works but I don't understand how a compressed file can be faster than an uncompressed one :confused: btw AB size has dropped drastically ( from 1.2 gb to 450 mb ) and loading time is two time faster, more or less. That's an amazing result!
    I'm implementing the loading with multiple coroutines as suggested, I did not in the past because I read that more than 1 AB loading coroutine could make app crash/freeze...I will share results when ready!
    Thanks a lot :)
     
  7. Neto_Kokku

    Neto_Kokku

    Joined:
    Feb 15, 2018
    Posts:
    1,751
    Phone CPUs are pretty fast nowadays, even in low-end devices. Phone storage is not: only high end phones have truly fast storage. Reducing the size of your files with compression will reduce loading times way more than the small extra time needed for the CPU to decompress the files.

    For parallel loading, you can try to limit the number of simultaneous bundles to load if you have problems loading everything at once. You can also try using a different packing strategy so you don't have to load as many small bundles, and load fewer larger ones instead.