Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
1
Question by Peter_Reflection · Jun 05, 2015 at 03:05 PM · assetbundlewwwhashloadfromcacheordownload

Save Hash128 from Asset Bundle Manifest

I am trying to build an asset bundle loading solution that will work both online and offline. I am able to download asset bundles with the WWW.LoadFromCacheOrDownload function but I'm having trouble loading them when there is no internet access.

First I download the main manifest file from the online location that contains the asset bundles. I then extract the names and Hash128s of the asset bundles from the manifest. I then use these values as the parameters in a WWW.LoadFromCacheOrDownload call to download the asset bundles from the internet. I am then storing these values in a local text file.

The plan is that when there is no internet connection I can load the names and Hash128s from the saved text file and use them as the parameters in a WWW.LoadFromCacheOrDownload call, it will recognise that the asset bundle is already downloaded and load it from the cache.

I have this all set up but the problem is with the Hash128 values. After retrieving them from the manifest I am converting them to a string in order to save them to the text file. When these Hash128s (that have been converted to strings) are read from the text file and parsed back into Hash128s they do not contain the original Hash128 value anymore. This means that the WWW.LoadFromCacheOrDownload function is not looking for the right asset bundle in the cache because the Hash128 that is used as the version is not the same, so it thinks there is a new version to download, which obviously doesn't work when offline.

My question is this: is there a way to save a Hash128 value to a local file without converting it to something else first?

Or is my solution for this way off?

I am using Unity 5.0.2f1.

Thanks for any help!

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 DungDajHjep · Jul 20, 2015 at 08:57 AM 0
Share

when there is no internet( if you sure ) get manifest file from cache , and you can get current hash ?

2 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Peter_Reflection · Jun 08, 2015 at 10:17 AM

I ended up finding the Hash128 function GetHashCode() that is not shown on the scripting API page. This returns an int which I am able to convert to a string and back again without the value changing. I am using this int as the version code in the WWW.LoadFromCacheOrDownload call and it all seems to work fine.

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
avatar image
2

Answer by ntchung · Jul 22, 2015 at 11:06 AM

GetHashCode might be a little risky because of collision, just use Hash128.ToString() and Hash128.Parse().

Save:

 Hash128 hash = assetBundleManifest.GetAssetBundleHash(assetBundlePath);
 streamWriter.WriteLine(hash.ToString());

Load:

 string textLine = streamReader.ReadLine();
 Hash128 hash = Hash128.Parse(textLine);

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

22 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

AssetBundle, problem whit the version 0 Answers

LoadFromCacheOrDownload is sensibly slower than WWW, why? 1 Answer

Save a prefab from asset bundle 1 Answer

How to download multiple asset bundles in serial order? The error of "cant load 'name' assetbundle as it is already loaded" comes after first assetbundle download. Please help. Needed urgently! 0 Answers

LoadFromCacheOrDownload non asset bundles 1 Answer


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