Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Voting for the Unity Awards are OPEN! We’re looking to celebrate creators across games, industry, film, and many more categories. Cast your vote now for all categories
    Dismiss Notice
  3. Dismiss Notice

Mess with multiple asset bundles

Discussion in 'Scripting' started by novaVision, Jul 16, 2018.

  1. novaVision

    novaVision

    Joined:
    Nov 9, 2014
    Posts:
    491
    Hi,

    I have stacked with multiple asset bundle system implementation. My idea was to split single but very large asset bundle ~200mb to many small bundles by 2-5mb. For bundle creation I use standard Unity Asset Bundle package.
    Let's see in details - before I had 4 files in bundle destination directory ../Asset Bundles/ios/
    1. bundleName
    2. bundleName.manifest
    3. ios
    4. ios.manifest
    To define, should asset bundle be re-downloaded or not I used these methods

    Code (CSharp):
    1.  
    2. string bundleUri = _assetBundlesUri + "ios/bundleName";
    3. string manifestUri = _assetBundlesUri + "ios/ios"
    4. //Get the AssetBundle
    5.                 AssetBundle manifestBundle = DownloadHandlerAssetBundle.GetContent(manifestRequest);
    6.                 AssetBundleRequest assetRequest =
    7.                     manifestBundle.LoadAssetAsync<AssetBundleManifest>("AssetBundleManifest");
    8.                 yield return assetRequest;
    9.  
    10.                 //Get the AssetBundleManifest
    11.                 AssetBundleManifest loadedAssetMf = assetRequest.asset as AssetBundleManifest;
    12.  
    13.                 //Get Hash128 from the AssetBundleManifest
    14.                 Hash128 tempHash128 = loadedAssetMf.GetAssetBundleHash(bundleName);
    15.  
    16.                 //Pass to the IsVersionCached function
    17.                 bool isVersionCached = Caching.IsVersionCached(bundleUri, tempHash128);
    Somehow I couldn't load "bundleName.manifest" directly to get Hash128, so I downloaded "ios" bundle directly to use GetAssetBundleHash. Everything worked fine with a single bundle, but nothing works with multiple.`There is no way to get Hash128 value for each bundle, because I can't download bundle manifest same as can't use "ios" bundle to get Hash.

    How to deal with this case? Obvious solution would be to download each bundle manifest file and grab Hash from there, but I didn't find a way to do it. Do I need to read hash from string and convert it to Hash128? As I remember I did it already in the beginning of bundle manager development, but Caching.IsVersionCached(bundleUri, tempHash128) always returned false.
     
  2. novaVision

    novaVision

    Joined:
    Nov 9, 2014
    Posts:
    491
    Really? Nobody had such case?
     
  3. nilsdr

    nilsdr

    Joined:
    Oct 24, 2017
    Posts:
    373
    I don't understand the problem, the implementation you suggested works just fine. You download and load the iOS top level manifest, you say you have that working.

    Code (CSharp):
    1. loadedManifest.GetAssetBundleHash(bundleName);
    Should then do the trick to get the per bundle hash and compare it to locally cached versions.

    If this isn't working let us know why not. any errors?
     
  4. novaVision

    novaVision

    Joined:
    Nov 9, 2014
    Posts:
    491
    wow... I wouldn't imaging that could work this way. Will test it ASAP.