Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Asset Bundle vs Build settings (how to get the same memory usage)

Discussion in 'Asset Bundles' started by Jenzo83, Jan 24, 2018.

  1. Jenzo83

    Jenzo83

    Joined:
    Oct 22, 2013
    Posts:
    34
    We have just started using asset bundles in our first live project. We've done quite a lot of testing and everything seems to work correctly(except for memory profiling on device). But after launch we've realized that a lot of lower end device that could play the game before suddenly are unable to start the game and or getting a lot of crashes. Also the loading times have increase quite a lot.

    But on higher end devices there are no issues at all.(except for the initial loading)


    We use the unity 2017.2 with the Asset Bundle Browser.

    This is the way we setup the project:

    We have one scene in the build settings of the game. This contains a script to load the initial asset bundles that are kept in streaming assets (scenes and duplicates). So they are included in the file.

    We use the Assetbundle browser to generate the duplicates that we load at startup, it's the duplicates between the scene bundles.


    Then later when players reach the third region of the game, that scene bundle is downloaded from a server.

    The two initial assetbundles(scenes and duplicates) are loaded with
    AssetBundle.LoadFromFileAsync()

    And then we load the third part we use the:
    WWW.LoadFromCacheOrDownload()

    If we just build a larger file that contains all the scenes directly in build settings and disable the bundles. Low-end devices have no problem running our game.

    We think the reason is increased memory usage. So now my question, how can we get the same or almost the same memory usage with bundles(in an as easy way as possible) as if the files were added in build settings?

    I'm afraid that the answer might be create a bundle for each scene... But I hope there is a better way!
     
  2. AlienMe

    AlienMe

    Joined:
    Sep 16, 2014
    Posts:
    93
    What compression are you using for the bundles? If you use standard compression (LZMA), then the bundles get loaded in memory... If you use chunked compression LZ4, then only the bundle 'directory' and asset info gets loaded.. but the actual assets are loaded on demand.

    We are doing something similar (whole project in asset bundles, using Asset Bundle Browser). To avoid duplicate assets, we had to jump through hoops. This is what we have:
    - Springboard scene (only scene included in Build Settings). No assets, just a script, loads Startup from bundle in Streaming Assets.
    - Startup scene, in a bundle, located in streaming assets. Contains splash, loading screen. Bootstrap code.
    - Bunch of other bundles. We have about 30+ asset bundles.

    We don't use LoadFromCacheOrDownload. Instead, we take care of downloading the files from the server, and always use LoadFromFileAsync.

    So far we managed to remove all duplicate assets, except for the image used by Unity's Splash Screen.

    We found that there is a cost of using the bundles.. of about 1-2 MB per opened bundle (without loading any assets).

    To find out where your memory is really going, run a dev build on your device, connect your Editor's profiler to the device, and in the memory 'section', choose a detailed report. There you can drill down, and see where your memory is going.

    Since you have the ability to run with and without bundles, you can do this for both scenarios.. and find out any difference in memory usage
     
    Jenzo83 likes this.
  3. Jenzo83

    Jenzo83

    Joined:
    Oct 22, 2013
    Posts:
    34
    Thanks for the reply! That really was the problem with the LZMA, did a couple of test runs with different setup. I did the same as you with an empty scene just to load up the bundles to reduce duplication to a minimum.

    I did some tests on our startup scene in the game on device, regarding how much memory is allocated.
    Just using buildsettings without any bundles: 220 mb
    Bundles compressed with LZ4: 260 mb
    Bundles compressed with LZMA: 382 mb

    Memory/speed wise LZ4 is absolutely preferable, but speed/memory is as seen above even better with buildsettings only.

    What I can't understand is why I can't get the same compression/speed/memory allocation with bundles as is achieved through unitys buildsettings.

    LZ4 is memory wise almost the same as buildsettings even though I really would like to be able to lose the last mb of memory. But filesize really explodes compared to the buildsettings build it's about 25% larger.

    Is there a way to get both with bundles? Am I missing something trivial maybe? Like would it be possible to convert LZMA bundles to LZ4 in runtime on the device?