- Home /
Why does nothing happen after yield return www
Ok first: I've seen quite similar questions about this and I've read through articles which explain the whole coroutine and yield structure. Unfortunately I still don't understand why this following code is not working. Basically I am downloading two files (a XML and a binary DAT file) and writing them to the disk afterwards. If you are interested in what the purpose of all of this is: I am making an Augmented Reality App with the Vuforia Framework and I need to download DataSets (which are needed for the image tracking).
private void LoadAndActivateDataSet ()
{
StartCoroutine (DownloadAndSave (baseURL, dataSet + ".xml"));
StartCoroutine (DownloadAndSave (baseURL, dataSet + ".dat"));
string myDataPath = Application.persistentDataPath + "/" + dataSet + ".xml";
LoadDataSet (myDataPath, DataSet.StorageType.STORAGE_ABSOLUTE);
}
IEnumerator DownloadAndSave (string url, string filename)
{
string remoteFile = url + filename;
string localFile = Application.persistentDataPath + "/" + filename;
Debug.Log ("remoteFile: " + remoteFile);
Debug.Log ("localFile: " + localFile);
// If the dataset already exists there will be no download
if (System.IO.File.Exists (localFile)) {
Debug.Log ("Exists: " + localFile);
Debug.Log ("No Download Required");
return true;
}
WWW www = new WWW (remoteFile);
yield return www;
System.IO.File.WriteAllBytes (localFile, www.bytes);
if (filename.EndsWith (".xml"))
Debug.Log (www.text);
}
And with the press of some GUI Button I just execute the method LoadAndActivateDataSet(). The code after yield return www; is not being executed, therefore the downloaded files won't be stored. I've done this the exact same with downloading an AssetBundle, which works very well and it is the exact same code.
So has anyone a clue what could be the problem? Am I misunderstanding the whole thing completely and I have some major error in there?
have you tried using www.progress to capture the download progress in a local float which you can debug? Then you can spot if the file is co$$anonymous$$g down
I wouldn't know where to set Progress, because right after WWW www = new WWW(remotefile); it would make no sense, as it will be always 0. And the code after yield return www; is never being executed.
you could have www
a public
variable and then just update another variable with www
's progress every Update
. Then you can see if at least something is happening :)
I was able to get it running now, but i think the code is completely horrific. I stopped doing Coroutines and i wait for download to finnish with the not so cool while(!www.isdone) endless loop till its downloaded. It works that way, but i think that's is not the proper way to do it and i seem to still not know how proper Coroutines are handled. Which was my initial intention of this question.