Search Unity

Mixing Asset Bundle Compression Type

Discussion in 'Editor & General Support' started by ratmat2002, Apr 6, 2016.

  1. ratmat2002

    ratmat2002

    Joined:
    Jun 13, 2014
    Posts:
    35
    Does anyone know if it is possible to mix AssetBundle compression types inside a single app?

    We have a mix of AssetBundles some of which are deployed with our binary in the StreamingAssets folder (we call these "local" AssetBundles) and some of which are deployed on our server (we call these "remote" AssetBundles). We want the "remote" AssetBundles to be able to have dependencies on the "local" AssetsBundles.

    If we build all of the AssetBundles in a single pass (using BuildPipeline.BuildAssetBundles with BuildAssetBundleOptions.ChunkBasedCompression), everything works fine.

    However, LZ4 (ChunkBasedCompression) is substantially larger than LZMA compression but about 30%. Ideally, we'd like to deploy LZ4-compressed "local" AssetBundles with our binary for super fast loading times and deploy LZMA-compressed "remote" AssetBundles on our server for faster download times.

    The Unity docs here (http://docs.unity3d.com/Manual/AssetBundleCompression.html) indicate this is the proper approach but don't make any mention of mixing compression types.
    1. Deploying asset bundles with your game as StreamingAssets - use BuildAssetBundleOptions.ChunkBasedCompression when building bundles and AssetBundle.LoadFromFileAsync to load it. This gives you data compression and the fastest possible loading performance with a memory overhead equal to read buffers.
    2. Downloading asset bundles as DLCs - use default build options (LZMA compression) and LoadFromCacheOrDownload/WebRequest to download and cache it. Here you’ll have the best possible compression ratio and AssetBundle.LoadFromFile loading performance for further loads.
    Is it possible to mix types while still maintaining automatic asset references between "local" and "remote" bundles?
     
    BabyRuman likes this.
  2. Deleted User

    Deleted User

    Guest

    It's not something you can do in a single pass, but if you separate to two passes, you do have problem about asset references...

    It's something we will evaluate to see if we should add to to-do list, will get you updated.
     
    BabyRuman likes this.
  3. ratmat2002

    ratmat2002

    Joined:
    Jun 13, 2014
    Posts:
    35
    Hi Vincent, I was going to follow up with you on another thread so I'm glad you confirmed this here.

    I think this would be an excellent optimization for the system. It would provide developers the best of both worlds when combining local (LZ4) and remote (LZMA) asset bundles.

    I can see this being implemented in a variety of ways. I think the simplest would be an additional signature for the BuildPipeline.BuildAssetBundles API. Something like shown below.

    The Dictionary would contain key-value pairs of assetBundleName to BuildAssetBundleOptions for that particular bundle. Any assetBundleNames not found in the dictionary would use the values contained in defaultAssetBundleOptions.

    public static AssetBundleManifest BuildAssetBundles(
    string outputPath,
    Dictionary<string, BuildAssetBundleOptions> assetBundleOptionsDict,
    BuildAssetBundleOptions defaultAssetBundleOptions,
    BuildTarget targetPlatform = BuildTarget.WebPlayer
    );
     
    BabyRuman likes this.
  4. sagar_unity999

    sagar_unity999

    Joined:
    Dec 20, 2017
    Posts:
    1
    hey is this implement in 2018 ???
     
  5. imaginalis

    imaginalis

    Joined:
    Feb 20, 2015
    Posts:
    29
    @Vincent-Zhang
    Wouldn't this be useful for separating crunched textures from other data on Android as an example?
    Currently I use LZ4 for all bundles but I guess separating it might speed up loading times for my usecase where I fill empty scene with instanced objects and most of them use crunched textures. I can't afford using uncompressed for everything on the other hand since it nearly doubles the APK size.

    Are there any news on this one?
     
  6. imaginalis

    imaginalis

    Joined:
    Feb 20, 2015
    Posts:
    29
  7. capyvara

    capyvara

    Joined:
    Mar 11, 2010
    Posts:
    80
  8. imaginalis

    imaginalis

    Joined:
    Feb 20, 2015
    Posts:
    29
    Thanks, this was what I was looking for! However I don't see any significant differences in load time so my assumptions were most probably wrong :)