Is it actually true that StopAllCoroutines stops WWWW downloads?

Say you do this,

loadLargeStupidImage();

and then this

function loadLargeStupidImage()
{
var fetcher:WWW = new WWW( some url );
yield fetcher;
fetcher.LoadImageIntoTexture(blah)l
}

Let’s say that takes 30 seconds for WWW to download the 7mb image.

Now let’s say at 3,n / 12.8 seconds you decide to stop doing this. So you call

StopAllCoroutines();

Now, new WWW() works like a coroutine, you can yield on it. If you StopAllCoroutines it correctly stops.

BUT does it actually stop the download mechanism? Are you still clogging up the bandwidth?

Is there, perhaps, some superior or more certain way to “stop a download in progress” with Unity? Cheers

Your right about fetcher.Dispose();

+1

But your coroutine doesn’t work that way :wink: when you do:

yield fetcher;

the coroutine will wait until the download is finished, so your boolean won’t be checked.

All you actually have to do is store the WWW object in a class variable so others can access it to call Dispose on it. Something like that:

// UnityScript
private var theWWWObject : WWW = null;

function StartDownload(url : String)
{
    theWWWObject = new WWW(url);
    yield theWWWObject;
    if (theWWWObject != null)
    {
        // Yey, finished!
    }
    else
    {
        // The download has been aborted
    }
    theWWWObject = null; // be GC friendly
}

function StopCurrentDownload()
{
    if (theWWWObject != null)
    {
        theWWWObject.Dispose();
        theWWWObject = null;
    }
}

I’m almost certain it won’t work. Don’t bother to test it, tho.

Certain and simple way to stop that download in progress: fetcher.Dispose();

You could use it in something like this:

while ( !fetcher.isDone ) {
  // do stuff
  if (anotherClassCalledThisToStop) {
    fetcher.Dispose();
    break;
  } else {
    yield return null;
  }
}