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
2
Question by Cellwind · Jul 22, 2010 at 07:48 PM · assetbundlewwwcache

Preloading asset bundles by unloading them after download - doesn't work with unity cache

I'm trying to preload asset bundles into the unity cache at runtime and also keep the memory footprint low, so I want to unload them as soon as they have been downloaded.

The problem I'm seeing is that once an asset bundle has been loaded from the cache, if it is unloaded and then loaded again, the WWW.LoadFromCacheOrDownload method will never finish. Sometimes it will load one or two files and then stop working. By never finish and stop working I mean that the WWW.isDone and WWW.progress never budge from false/0.

There doesn't seem to be any documentation for the Caching object nor the WWW.LoadFromCacheOrDownload method and there is barely a mention of either on the forums or anywhere I can find.

I've been up all night trying to find a workaround for this. I've been testing this in the editor, so perhaps it is a problem with just the editor's usage of the cache. One theory I have is that something is holding open file handles so that when the cache file is requested again it can't open it. I've also been able to get the editor to hang or crash doing things to WWW.assetBundle, even referencing it after calling Unload on it, or not calling Dispose on the WWW object or calling it in some improper order. The consequence is that the unity editor process will hang with processor usage at 0%. I changed some stuff to delay calling AssetBundle.Unload until the next frame which makes me think there is some re-entrancy problem with immediately unloading a bundle after referencing the WWW.assetBundle. Just touching WWW.assetBundle does some funky things itself. Doing if(WWW.assetBundle != null) will sometimes cause an exception to be thrown.

If anybody has some info on caching, I'd really appreciate it.

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 Cellwind · Jul 22, 2010 at 10:47 PM 0
Share

Another interesting note from further testing: If I am waiting for the WWW to complete by polling isDone and progress inside a coroutine, the app will just hang unless I add a WaitForSeconds in there where the wait is 0.4 or greater. If I put in 0.3 then it hangs sometimes. Don't know what this is about.

3 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Cellwind · Jul 23, 2010 at 02:06 AM

A couple of updates:

I changed the WWW download wait to the following and it cleared up a lot of the hanging issues:

// Wait for the load to complete // while(_activeLoadStream != null) { if(_activeLoadStream.isDone || _activeLoadStream.progress == 1.0f) { break; }

     yield return _activeLoadStream;
 }

I also put in a wait timer after calling either Caching.DeleteFromCache or Caching.CleanCache to make sure the operation has time to complete before attempting to load any other assets through WWW.LoadFromCacheOrDownload. My theory was that if the cache deletion was delayed at all (perhaps due to open file handles or whatever), that an immediate load and subsequent write into that same cache directory would then get clobbered by the delayed cache delete, causing the cache to go into an inconsistent state.

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
0

Answer by jonas-echterhoff · Jul 23, 2010 at 08:42 AM

Note that the WWW APIs (both in Cached or Uncached forms) are not completely asynchronous. That means that doing

WWW myDownload = new WWW (url);
while (! myDownload.isDone );

will result in an infinite loop, at least when used on an asset bundle. The reason is that Unity needs some time in it's game loop to integrate download objects from the AssetBundle, which cannot all be done on a thread. So, you need to give back control to Unity while waiting for the download to finish.

The preferred way of doing that (as you seem to have found out yourself), is to do a

yield return myDownload;

, which will resume your script when the download is finished.

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
0

Answer by disturbing · Oct 10, 2011 at 11:42 PM

I reported this problem.

The issue is isDone is doing some kind of logic that update progress. isDone must be called in order for progress to be updated.

I reported this to unity and this problem still exists in Unity 3.4.1

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

1 Person is following this question.

avatar image

Related Questions

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

Issues with WWW.LoadFromCacheOrDownload 2 Answers

Clean Cache on Mobile 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