Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
2
Question by iMagesBlues · Jun 22, 2016 at 05:09 AM · cacheassetbundlesmanifesthash

How to save and load a copy of the AssetBundleManifest file

Hi guys,

Using Unity's Asset Bundle System, I am trying to achieve the following behaviour:

  1. When app opens, if wifi connection is present, download the manifest file from cloud.

  2. If no wifi available, load an older version of the manifest from cache.

However, from Unity's asset bundle demo, the manifest file is always downloaded from the cloud via this code:

WWW download = new WWW (url);

whilst non-manifest files are downloaded using:

WWW download = WWW.LoadFromCacheOrDownload (url, m_AssetBundleManifest.GetAssetBundleHash (assetBundleName), 0));

I tried a couple of things such as using LoadFromCacheOrDownload() when new WWW() has failed (wifi not present) but I'm not sure what hash to use for the manifest file.

I can also see this comment: "For manifest assetbundle, always download it as we don't have hash for it." but still my heart wishes to achieve the behaviour mentioned.

Any help or insight is greatly appreciated. :)

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image iMagesBlues · Jun 21, 2016 at 03:19 AM 0
Share

I also tried saving and loading a copy of the AssetBundle$$anonymous$$anifest object via X$$anonymous$$L/Binary Serialization but still didn't work (I'm getting many different errors in serialize/deserialize) maybe because it is not a serializable class.

How does Unity do it anyway?

1 Reply

· Add your reply
  • Sort: 
avatar image
2

Answer by Iseebees · Jul 22, 2016 at 07:38 PM

If you're using Unity's Asset Bundle Manager, open the AssetBundleManager.cs script. Within that script, there's an Update() function that checks for finished downloads. The manifest file does not have an asset bundle name, unlike other assets, so check for a finished download that doesn't have a name, and it will be the main manifest file.

First, find the Update() function in AssetBundleManager.cs. There's a comment "If downloading succeeds". Find it. That's where you'll start.

NOTE: There is another newer,version of the AssetBundleManager on Bitbucket. If that's the version you're using you can grab the finished download in the AssetBundleLoadOperation.cs script, just before m_www.Dispose(); and m_www = null;

Here's an excerpt from for the Update function, along with where you can capture the manifest it downloads.

     private static AssetBundleManifest my_Manifest;
     void Update(){
     
     // ...code omitted from this example
     
     // If downloading succeeds.
     
     if (download.isDone) {
                             
          AssetBundle bundle = download.assetBundle;
     
          if (bundle == null) {m_DownloadingErrors.Add (keyValue.Key, string.Format ("{0} is not a valid asset bundle.", keyValue.Key));
     
          keysToRemove.Add (keyValue.Key);
         continue;
     }
     
         //Here's where we grab the manifest
         
         if (download.assetBundle.name == "") {
         
              StartCoroutine (WaitToSaveManifest (www));
         }
     }
     
     //here's where the manifest is saved to the disk
                 public IEnumerator WaitToSaveManifest(WWW www){
     
                     string savePath = Application.persistentDataPath + Path.DirectorySeparatorChar + "iOS.bytes";
     
                     File.WriteAllBytes (savePath, www.bytes);
         
         //            ensure download bundles are not backed via iCloud, or your app will be rejected by Apple
                     UnityEngine.iOS.Device.SetNoBackupFlag(savePath);
         
         }
     
     //here's how to retrieve the manifest file from the bytes file that was saved to the disk
     IEnumerator OfflineLoading(){
     
             byte[] readAssBytes = File.ReadAllBytes (Application.persistentDataPath + Path.DirectorySeparatorChar + "iOS.bytes");
             
             AssetBundle acr = AssetBundle.LoadFromMemory (readAssBytes);
             yield return acr;
     
             AssetBundleManifest readAssetBundle = (AssetBundleManifest)acr.LoadAsset ("AssetBundleManifest");
             yield return readAssetBundle;
             my_Manifest = readAssetBundle;
     //Don't initialize the asset bundle manager because it will try to download the manifest from your server and throw an error. 
 //Instead, take your local manifest that you loaded from the disk, and give it to the Asset Bundle Manager, like so:
             AssetBundleManager.AssetBundleManifestObject = readAssetBundle;
 
     //Done!
         }


I imagine there are more elegant solutions to this problem. If you'd prefer to avoid altering the code in Unity's Asset Bundle Manager, you could download the manifest yourself using WWW.LoadFromCacheOrDownload and passing in the address to the manifest file, instead of intercepting the one that the ABM is downloading.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Why was the method overload for Caching.IsVersionCached that accepts an integer instead of a Hash128 made obsolete if UnityWebRequest's GetAssetBundle method still takes an integer version number as input? 0 Answers

AssetBundle Saving? 1 Answer

Get Hash from streamed scene asset bundle 1 Answer

Caching Unity Web Request downloaded Asset Bundles denied by iOS 0 Answers

Addressable Assets Cache 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges