Search Unity

Help to load manifest

Discussion in 'Asset Bundles' started by TheGoodDrive, Jul 2, 2018.

  1. TheGoodDrive

    TheGoodDrive

    Joined:
    Sep 23, 2015
    Posts:
    9
    Hi all,

    I have big problems to load manifest to find dependencies.

    I try to load a bundle "city.hdgermany" which have a dependence to bundle "datas", I follow the doc to load manifest ( even with half of doc obsolete) with this code from https://docs.unity3d.com/Manual/AssetBundles-Native.html

    Code (CSharp):
    1.  
    2.            var uri              = Application.streamingAssetsPath + "/" + DataAssetBundle;
    3.             AssetBundle assetBundleDatas = AssetBundle.LoadFromFile(uri);
    4.  
    5.                   uri = Application.streamingAssetsPath + "/" + MainAssetBundle;
    6.             var assetBundle = AssetBundle.LoadFromFile(uri);
    7.             AssetBundleManifest manifest;
    8.  
    9.             {
    10.                 manifest = assetBundle.LoadAsset<AssetBundleManifest>(MainAssetBundle + ".manifest");
    11.                 // or AssetBundleManifest same result
    12.             }
    13.  
    14.             string[] dependencies = manifest.GetAllDependencies(MainAssetBundle);
    15.            //Pass the name of the bundle you want the dependencies for.
    16.  
    17.             foreach (string dependency in dependencies)
    18.             {
    19.                 Debug.Log(dependency);
    20.             }
    21.  
    22.             yield break;
    23.         }
    24.  
    25.         #region Variables
    26.  
    27.         private const string MainAssetBundle = "city.hdgermany";
    28.         private const string DataAssetBundle = "datas";
    29.  
    30.         #endregion
    manifest is always null ....

    Also manifest cannot be used with scene streaming assetbundle ? so how do you know dependencies ?

    Thks for help !
     
  2. bfe_gio

    bfe_gio

    Joined:
    Apr 7, 2016
    Posts:
    9
    When you generate AssetBundles, the manifest object gets put into its own bundle, which will be named after the folder the AssetBundles got built to. So if you built to a folder called "MyAssets", you'd have all your bundles, plus one called "MyAssets". In your case it looks like you've got them directly in StreamingAssets, so if that's where you built to you'll have a bundle file called "StreamingAssets". This bundle should be loaded separately - It contains exactly one asset, called "assetbundlemanifest", which is the AssetBundleManifest object.

    So you'd need something like:
    Code (CSharp):
    1. var manifestUri = Application.streamingAssetsPath + "/StreamingAssets";
    2. var manifestBundle = AssetBundle.LoadFromFile(manifestUri);
    3. AssetBundleManifest manifest = manifestBundle.LoadAsset<AssetBundleManifest>("assetbundlemanifest");
    4.  
    5. // Now you can do stuff with the manifest
    (replace "/StreamingAssets" with whatever your manifest bundle file is called)
     
    chico_barnstorm likes this.
  3. TheGoodDrive

    TheGoodDrive

    Joined:
    Sep 23, 2015
    Posts:
    9
    I see, thanks @bfe_gio .
    I will try that !
     
  4. Gengseng

    Gengseng

    Joined:
    Feb 25, 2017
    Posts:
    5
    When you generate AssetBundles, the manifest object gets put into its own bundle, which will be named after the folder the AssetBundles got built to. So if you built to a folder called "MyAssets", you'd have all your bundles, plus one called "MyAssets". In your case it looks like you've got them directly in StreamingAssets, so if that's where you built to you'll have a bundle file called "StreamingAssets". This bundle should be loaded separately - It contains exactly one asset, called "assetbundlemanifest", which is the AssetBundleManifest object.

    이건 거의 뭐 예수님의 답변이다. 할렐루야! FolderName의 AssetBundle에 접근해야 한다는 답변은 이게 유일하다. 왜 제대로 받아온 AssetBundle 내부에 AssetBundleManifest가 존재하지 않고 널 에러가 나는지, 도대체 AssetBundleManifest가 '어디에' 있는지 조차 몰랐는데 한 번에 해결했다. AssetBundleManifest를 가져와야 할 목적지 자체가 달랐다는 것을 이 Human Navigation이 잘 설명해주었습니다. 이 사람이 절벽을 향해 돌진하는 내 핸들을 꺾어서 목숨을 살렸습니다. Thank you sir.
     
    Last edited: Jan 20, 2020
unityunity