- Home /
The question is answered, right answer was accepted
Ienumerator is being called even when not told to
The problem happens when I open it in Android. This works perfectly on PC Summary: when file is not detected it will download and save it persistent data path and if the file is detected it wont run the IEnumerator SaveAndDownload() but somehow it keeps downloading even with multiple conditions
void Awake()
{
m_builder.GetComponent<Image>();
filename = Application.persistentDataPath + "/" + filename;
alreadyDownloaded = File.Exists(filename);
if (!alreadyDownloaded)
{
StartCoroutine(SaveAndDownload());
}
else
{
m_progress.GetComponent<Text>().enabled = false;
StopAllCoroutines();
StopCoroutine(SaveAndDownload());
LoadAsset();
}
}
private IEnumerator SaveAndDownload()
{
WWW www = new WWW(url.Trim());
while (!www.isDone)
{
m_builder.SetActive(false);
m_progress.text = "Downloading \n" + Mathf.Round(www.progress * 100).ToString();
m_progress.text += "/100%";
Debug.Log(string.Format("Downloaded {0:P1}", www.progress));
yield return new WaitForSeconds(.05f);
if (File.Exists(filename) == true && alreadyDownloaded == true)
{
m_progress.GetComponent<Text>().enabled = false;
StopAllCoroutines();
StopCoroutine(SaveAndDownload());
}
else m_progress.GetComponent<Text>().enabled = true;
}
yield return www;
byte[] bytes = www.bytes;
File.WriteAllBytes(filename, bytes);
if (www.isDone)
{
StopAllCoroutines();
StopCoroutine(SaveAndDownload());
LoadAsset();
}
}
Please help thanks in advance
Answer by jandd661 · Sep 15, 2018 at 01:40 PM
Greetings, The first thing to check is if filename = Application.persistentDataPath + "/" + filename;
returns what you expected on Android. I do believe the "/" should be "\" but I could be wrong. Also, a self referencing concatenation is prone to change results.
I checked android and it uses "/" I also fixed the self referencing concatenation and it gave me same result. Like it gives both true and false at the same time from my if/else condition inside the Awake(); function
Thanks for the recommendation btw: $$anonymous$$uch appreciated :D