Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 11 Next capture
2021 2022 2023
1 capture
11 Jun 22 - 11 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
5
Question by Tomer-Barkan · Jul 08, 2015 at 06:38 AM · assetbundlewwwcache

Issues with WWW.LoadFromCacheOrDownload

We're having issues with caching of AssetBundles in iOS. We download the manifest, then download and load all of the AssetBundles in the manifest before the game starts. Everything is downloaded properly and the game works fine.

Next time we launch the game, however, some of the using WWW.LoadFromCacheOrDownload (http://docs.unity3d.com/ScriptReference/WWW.LoadFromCacheOrDownload.html), with the exact same version as before (same version is used for all the AssetBundles), 90% of the AssetBundles are loaded from cache, but a few are downloaded again, even though nothing changed in the bundles, their version, or the version we provide. Has anyone ever encountered this? Any solutions?

Comment
Add comment · Show 2
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 TobyKaos · Jul 08, 2015 at 07:34 AM 0
Share

Are there a cache limit size on iOs?

avatar image Tomer-Barkan · Jul 08, 2015 at 07:42 AM 0
Share

According to unity docs the limit is 4GB: http://docs.unity3d.com/ScriptReference/Caching-maximumAvailableDiskSpace.html

2 Replies

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

Answer by pitimoi · Jul 08, 2015 at 08:39 PM

Hi Tomer,

According to the Unity LoadFromCacheOrDownload documentation :

If the cache folder does not have any space for caching additional files, LoadFromCacheOrDownload will iteratively delete the least-recently-used AssetBundles from the Cache until sufficient space is available to store the new AssetBundle. If making space is not possible (because the hard disk is full, or all files in the cache are currently in use), LoadFromCacheOrDownload() will bypass Caching and stream the file into memory like a normal "new WWW()" call.

Then yes, it is possible that some assetbundle will be downloaded again if the cache does not have enough space to download everything.

Edit :

If you want to make sure that your assetbundle will always be available while the player is offline, the only way to go is to NOT use the LoadFromCacheOrDownload on assetbundle from the server and download them yourself. Here is how I did it on my side :

  1. Build your assetbundle and create a json file (or xml or whatever...) which contains for each assetbundle the version number and a md5 hash of its binary.

  2. When the player launch the game, read the json file from your server and compare the version number between the player saved game and the server current value. If it is the same, check the md5 hash (just to be sure it is nor corrupted).

  3. If the version from the server is newer or the md5 hash differs, download the package from the server using new WWW() and save it as the new version. You should be able to save it in the Application.persistantDataPath but be careful on iOS with the cloud save game which may try to save all the assetbundle in the cloud (it will be a cause of failure while submitting if so).

  4. When everything is done, the player got a downloaded version of each assetbundle and a file (json, xml, encrypted binary...) which contains the current version of each assetbundle in its saved game directory. At this point, you can use the LoadFromCacheOrDownload using your local path and the current assetbundle version to use all your assetbundle like if you were online, avoiding any caching limitation.

This solution does not works for a WebPlayer build because you cant save any binary file on the disk with this build target

Comment
Add comment · Show 6 · 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 Tomer-Barkan · Jul 08, 2015 at 08:42 PM 0
Share

Thanks, but this is not the case, there is plenty of disk space and we're not near the 4GB limit.

avatar image pitimoi · Jul 08, 2015 at 09:05 PM 1
Share

You can still have a look on the Caching class which may have helpful methods for you (like the expirationDelay value).

Because of this kind of problems I don't rely on the LoadFromCacheOrDownload method anymore to use my assetbundle and created a lot of workarounds to avoid it.

The only place where I still use LoadFromCacheOrDownload is with WebPlayer because we don't have any choice, and we don't really take care on how many times an assetbundle will be re-downloaded ins$$anonymous$$d of being re-used from the cache on this platform.

avatar image Tomer-Barkan · Jul 09, 2015 at 01:22 AM 0
Share

Yeah, I guess at its current state, writing your own caching mechanism is the way to go... If you can edit your answer and explain how you created your caching mechanism I can accept the answer so others can see.

avatar image pitimoi · Jul 09, 2015 at 02:33 AM 0
Share

I updated my answer with more informations about how I handle this problem, thanks :)

avatar image Tomer-Barkan · Jul 13, 2015 at 07:23 AM 0
Share

Thanks. If/when we end up implementing this I'll let you know how it goes.

Show more comments
avatar image
0

Answer by Inessa · Nov 01, 2016 at 03:20 PM

@pitimoi I am trying to implement pitimoi's approach to hadle AssetBundles, but I faced a lot of difficulties.

Can anybody share C# script implementing this approach?

Thank you in advance.

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

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

Related Questions

how to delete specific files from cache? 3 Answers

LoadFromCacheOrDownload is sensibly slower than WWW, why? 1 Answer

How to determine validity of cached asset bundle 1 Answer

Progress when using WWW.LoadFromCacheOrDownload 2 Answers

Preloading asset bundles by unloading them after download - doesn't work with unity cache 3 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