- Home /
Progress when using WWW.LoadFromCacheOrDownload
I just switched from using new WWW()to WWW.LoadFromCacheOrDownload and it works fine. However the progress value always remains zero.
void OnClick()
{
StartCoroutine(DownloadAndCache(sceneName));
while (_cachedAssetBundle.progress < 1)
{
Debug.Log(string.Format("Progress - {0}%. from {1}", _cachedAssetBundle.progress * 100, _cachedAssetBundle.url));
}
}
private IEnumerator DownloadAndCache(string sceneName)
{
WWW cachedAssetBundle = WWW.LoadFromCacheOrDownload(sceneName, 1);
yield return _cachedAssetBundle;
}
Similar post:
http://forum.unity3d.com/threads/138798-LoadFromCacheOrDownload-progess-bar
Has anyone else encountered this problem? (Not yet tested on Unity 4) Any solutions?
I've edited the question because I still don't have the solution.
Answer by straris2 · Sep 26, 2013 at 08:43 PM
I have putted the progress in the Update function and works for me:
var scene: String;
var path: String;
var download: WWW;
function Start () {
download = WWW.LoadFromCacheOrDownload (path, 5);
yield download;
// Handle error
if (download.error != null)
{
Debug.LogError(download.error);
return;
}
var bundle = download.assetBundle;
}
function Update () {
Debug.Log("Downloading"+download.progress);
}
}
Your download.progress is going to be either 0 or 1. So the problem that ZenithCode's mentioned still remains unsolved.
Actually the download.progress gets values from 0 to 1 the tricky part is to be able to listen to that change. As mentioned, the above code worked for me and i used it in a working loading bar. You can find the result here. (the loading bar is a cube that spins and fills in slowly) http://hellenicshoppingcenters.gr/index.php?lang=el
Yeah, it did work for me, but I had to use wwwObject.isDone ins$$anonymous$$d of yield returning the wwwObject. e.g. following code did give the progress from 0 to 1.
wwwData = WWW.LoadFromCacheOrDownload( abData.m_strUrl, abData.m_iBundleVersion );
while( !wwwData.isDone )
{
m_fDownLoadProgress = wwwData.progress;
yield return null;
}
Answer by morettyCat · Mar 21, 2019 at 11:24 PM
I think the problem is that your are using a while inside a void. It will not wait until IEnumerator finish... You need tu put your while inside IEnumerator before your yield!
I Know maybe it's too late, but maybe for future problems!
private IEnumerator DownloadAndCache(string sceneName){
WWW cachedAssetBundle =WWW.LoadFromCacheOrDownload(sceneName, 1);
while (_cachedAssetBundle.progress < 1){
Debug.Log(string.Format("Progress - {0}%. from {1}",_cachedAssetBundle.progress * 100, _cachedAssetBundle.url));
}
yield return _cachedAssetBundle;
}
Your answer
Follow this Question
Related Questions
Clean Cache on Mobile 0 Answers
how to delete specific files from cache? 3 Answers
How to determine validity of cached asset bundle 1 Answer
LoadFromCacheOrDownload is sensibly slower than WWW, why? 1 Answer
Issues with WWW.LoadFromCacheOrDownload 2 Answers