Need Coroutine Download to finish first

Hi guys, maybe you can save me two days of crying. So here’s my issue, I have a program that stores files server side that I need to be client side (lots of reasons for this). At times the number of files to download may be large, some times they may be small (all depends on if the server has the more recent file or not). That being said I have the download coroutine set up and the script works in so far as figuring out what files need to be downloaded, BUT, due to the way coroutines go (as if I really understand it) it doesn’t finish downloading till the end of the script (which because I use variables to pass file paths means only one file eventually gets downloaded).

SO, in short I need to wait for each download to complete prior to moving on in the code. I’ve viewed several responses on this subject but none of them made sense to me and I was hoping someone could help guide me onto the answer.

    public void CompareLists()
    {
     //do a lot of stuff
                if (LocalFileList.Contains(ComparisonText))
                {
                  //do some more sorting
                    if (LocalFileDate <= AWSFileDate)
                    {
                        StartCoroutine( WaitForRequest());
                        Debug.Log("last");
                    }
                }
                else
                {
                    StartCoroutine(WaitForRequest());
                    Debug.Log("last");
                }
            }
        }
    }
 
    IEnumerator WaitForRequest()
    {
  //do some junk here like define url and filepath
            WWW www = new WWW(filepath));
            yield return www;
            File.WriteAllText(filepath,www.text);
    }

So like I said this whole thing works EXCEPT I need one coroutine to finish before moving on, I deleted a lot of fluff and logic to make the code string shorter. Thanks for your time.

Here’s how you wait for a download.

  1. instead of following every example out there that says to yield return www right after calling WWW www, put yield return null at the end.
  2. Add the code: while(!www.isDone){} so that it waits for the isdone to do anything with the information you just downloaded. (probably want to add a timeout for this)

Feedback is still welcomed, I’m a noob afterall.