4

I am new in Unity and and I start to use AssetBundle for my project to download them from server. I use UnityWebRequestAssetBundle to download the assets because WWW is obsolete. Everything is works fine I can download the assets from the server put it into the persistentDataPath and I can load them to the scene without any problem. But then I realised that there may be a chance when the model is get updated so I also need to update it in the app. I know there is a manifest file for every asset in the assetbundle so when I download the asset I also download the manifest file. I do everything as the Unity documentation but I always get this error:

unable to read header from archive file: /manifest/location

The manifest download method looks like this:

IEnumerator GetManifest(string animal)
{
    using (UnityWebRequest uwr = UnityWebRequestAssetBundle.GetAssetBundle("http://weppage.com/" + asset + ".manifest"))
    {
        uwr.downloadHandler = new DownloadHandlerFile(path + "/" + asset + ".manifest");
        yield return uwr.SendWebRequest();

        if ( uwr.isNetworkError || uwr.isHttpError )
        {
            Debug.Log(uwr.error);
        }
    }
}

Then there is the check method after download:

    AssetBundle manifestBundle = AssetBundle.LoadFromFile(Path.Combine(path, asset));
    AssetBundleManifest manifest = manifestBundle.LoadAsset<AssetBundleManifest>("asset.manifest");

I'm totally lost. I go through the google and I can't get it work. I don't get why it isn't work. I load the asset the same way without any problem and Unity docs said it have to work the same way. From Unity docs: Loading the manifest itself is done exactly the same as any other Asset from an AssetBundle

Máté Nagy
  • 125
  • 8

1 Answers1

0

The file you need to load in AssetBundle.LoadFromFile is a file that is generated in the same folder you stored your AssetBundle. This file gets the same name as the folder is stored in. For example, if you generated an AssetBundle called maps in a folder called bundles, a file bundles is going to be generated along with maps. This way, in AssetBundle.LoadFromFile you would have to load the file bundles. In any case you have to load any .manifest file. Your code would be like this:

IEnumerator GetManifest(string animal)
{
    using (UnityWebRequest uwr = UnityWebRequestAssetBundle.GetAssetBundle("http://weppage.com/" + asset))
    {
        uwr.downloadHandler = new DownloadHandlerFile(path + "/" + asset);
        yield return uwr.SendWebRequest();

        if ( uwr.isNetworkError || uwr.isHttpError )
        {
            Debug.Log(uwr.error);
        }
    }
}

And your check method after download:

AssetBundle manifestBundle = AssetBundle.LoadFromFile(Path.Combine(path, "bundles")); //the name of the example file I gave you
AssetBundleManifest manifest = manifestBundle.LoadAsset<AssetBundleManifest>("AssetBundleManifest");
Jon Iturmendi
  • 51
  • 1
  • 6