Search Unity

How to get AssetBundleManifest?

Discussion in 'Scripting' started by ViktorAcadem, Sep 15, 2017.

  1. ViktorAcadem

    ViktorAcadem

    Joined:
    Jun 30, 2016
    Posts:
    11
    Following the instructions on the official site https://docs.unity3d.com/ScriptReference/Caching.html I fail to get AssetBundleManifest neither from the server nor from local storage. The end goal is to get AssetBundle’s hash.

    Main error message in the console is:

    Failed to decompress data for the AssetBundle "Memory"

    I tried to use the following:

    UnityWebRequest - to load from server

    LoadFromFile - to local from local storage

    How to do it correctly?
     
  2. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    2,248
    Can you show the code?
     
  3. ViktorAcadem

    ViktorAcadem

    Joined:
    Jun 30, 2016
    Posts:
    11
    After building I receive the main file and the manifest file.

    In order to check cache and the updated bundle loading I have to indicate hash of the new Bundle which we can obtain only from AssetBundleManifest(for UnityWebRequest). However I cannot make AssetBundleManifest load properly. I tried to indicate path both to the main file (without extension), and to the manifest file (with .manifest extension)

    I try to load AssetBundleManifest using these lines:
    Code (CSharp):
    1.  
    2. AssetBundle manifestBundle = AssetBundle.LoadFromFile(Path.Combine(Application.streamingAssetsPath, "dispatcherminigame.manifest"));
    3. AssetBundleManifest manifest = manifestBundle.LoadAsset<AssetBundleManifest>("AssetBundleManifest");
    So in order to get AssetBundle’s hash I have to load the file with .manifest extension, right?
     
  4. Jean-Fabre

    Jean-Fabre

    Joined:
    Sep 6, 2007
    Posts:
    336
    Hi,

    I am struggling with this too.

    Is it a matter of downloading the manifest individually, or is it indeed available within the loading bundle?

    Bye,

    Jean
     
  5. nilsdr

    nilsdr

    Joined:
    Oct 24, 2017
    Posts:
    193
  6. Jean-Fabre

    Jean-Fabre

    Joined:
    Sep 6, 2007
    Posts:
    336
    Hi,

    thanks for your reply.

    the problem is that I can't find the way to do what you say with code.

    I have this:

    AssetBundleManifest _m = (AssetBundleManifest)wwwObject.assetBundle.LoadAsset("AssetBundleManifest", typeof(AssetBundleManifest));

    and that doesn't work, so I would appreciate a snippet on what to do with the wwwObject.assetBundle once it's done being downloaded, so far I haven't found a working snippet from all my searches on google.

    AssetBundleManifest _m = (AssetBundleManifest)wwwObject.assetBundle.mainAsset;

    that doesn't work neither.

    so if you have a working code snippet to share, I would appreciate it very much.

    Bye,

    Jean
     
  7. nilsdr

    nilsdr

    Joined:
    Oct 24, 2017
    Posts:
    193
    Code (CSharp):
    1. wwwObject.assetBundle.LoadAsset<AssetBundleManifest>("assetbundlemanifest");
    Should work. If not, define what 'doesn't work' means. Do you get an error?

    Also, the bundle containing the manifest is the one named after the folder you built to. It also isn't the file with the .manifest extension, its the bundle file which doesn't have an extension.
     
    Last edited: Aug 23, 2018
  8. Jean-Fabre

    Jean-Fabre

    Joined:
    Sep 6, 2007
    Posts:
    336
    Hi,

    That doesn't work neither, this line returns null, while the assetbundle main asset is well and can be accessed properly.

    here's the url : https://www.dropbox.com/s/bmunwj8c3ohtfoi/bundletest?dl=1

    Maybe you could point me to a url of a testing asset bundle that works? that would be a good way to rule out that the production of this assetbundle is faulty.

    and I confirm that the .manifest is not the file I load, but indeed the other one, without extension.

    thanks for your patience on this :) I hope we'll get to the bottom of this!

    Jean
     
  9. nilsdr

    nilsdr

    Joined:
    Oct 24, 2017
    Posts:
    193
    Hi Jean,

    Your bundle returns null on my end too, but I'm using unity 2018.2.2f1 and your manifest is built using 5.6.3f1 by the looks of it (bundles aren't guaranteed to be compatible with different versions).

    What Unity version are you using to build the bundles and project?

    Also, post your downloading code. I suppose unitywebrequest isn't available yet in 5.6.

    Here's an example of a bundle that works for me:

    https://s3-eu-west-1.amazonaws.com/byardev.mysmilez.nl/Android
     
  10. Jean-Fabre

    Jean-Fabre

    Joined:
    Sep 6, 2007
    Posts:
    336
    Hi,

    yes, it's built with 5.6, but it should work still right?! I'll move to 2017 and 2018 to see if I get a different results.

    I need to get to the lowest working version as I am providing support for PlayMaker, so it woul dbbe good if I can make it work on 5.6

    Bye,

    Jean
     
  11. nilsdr

    nilsdr

    Joined:
    Oct 24, 2017
    Posts:
    193
    Out of curiosity I downloaded the unity version the bundles were built in, and I can't load the manifest either.

    What build target was the bundle built for? It has to be the same as the platform you try to load it on.

    Post the script used to generate the bundles, and the script that downloads them.
     
  12. Jean-Fabre

    Jean-Fabre

    Joined:
    Sep 6, 2007
    Posts:
    336
    Hi,

    I am doing this all in editor for standaloneOsX platform target. does that means it will never work in editor?

    Bye,

    Jean
     
  13. nilsdr

    nilsdr

    Joined:
    Oct 24, 2017
    Posts:
    193
    No, it should load in the editor.

    I just used this build script in the same unity version as you to generate a manifest

    Code (CSharp):
    1. using System.IO;
    2. using UnityEditor;
    3.  
    4. public class CreateAssetBundles
    5. {
    6.     [MenuItem("Assets/Build AssetBundles")]
    7.     static void BuildAllAssetBundles()
    8.     {
    9.         string assetBundleDirectory = "Assets/AssetBundles";
    10.         if(!Directory.Exists(assetBundleDirectory))
    11.         {
    12.             Directory.CreateDirectory(assetBundleDirectory);
    13.         }
    14.        
    15.         BuildPipeline.BuildAssetBundles(assetBundleDirectory, BuildAssetBundleOptions.None, BuildTarget.StandaloneOSXUniversal);
    16.     }
    17. }
    It outputs this bundle: https://s3-eu-west-1.amazonaws.com/byardev.mysmilez.nl/AssetBundles

    And it loads just fine using the previously shared code. The problem has to be in the bundle file itself, try recreating it.

    This could even be a problem with dropbox hosting. Perhaps they use some funky compression which messes up the file, try regenerating the bundles and hosting it elsewhere or even in streaming assets.
     
  14. Jean-Fabre

    Jean-Fabre

    Joined:
    Sep 6, 2007
    Posts:
    336
    Hi,

    ok, thanks for confirming on your end that works, I'll debug this Id save it in StreamingAssets already. but as I was loading it from that and was getting null I though it could be something that is only available when you download from the web hence why I tried to put it on the web.

    thanks for your help!

    Bye,

    Jean
     
  15. Nith666

    Nith666

    Joined:
    Aug 1, 2012
    Posts:
    21
    I came across this thread as I had the same problem. I think your mistake is that you're looking in the wrong files. When you create the asset bundles, Unity creates 2 files in your output folder, named after the build target, e.g. WebGL and WebGL.manifest. In order to retrieve the AssetBundleManifest with
    Code (CSharp):
    1. wwwObject.assetBundle.LoadAsset<AssetBundleManifest>("assetbundlemanifest");
    You need to use the file "WebGL" (without the extension). With that AssetBundleManifest you can get all the info needed about the actual AssetBundles
     
  16. Jean-Fabre

    Jean-Fabre

    Joined:
    Sep 6, 2007
    Posts:
    336
    Hi,

    Thanks for your Input!

    Bye,

    Jean