WWW class and download errors detection

I’m experiencing big trouble with this.

I could setup my game with assetbundles for webplayer and all is working fine, I can download the assets, instantiate in the proper order and all works, but then I tried to figure out what happens when something fails.

So I forced an error just changing the url for the assets to an unreachable one (just added some random letters to the assetbundle file name), and here starts the nightmare.

First I’ll explain what’s happening and later some things I found on the way. I used for this a modified version of the InstantiateResource from the AssetBundles example project.

When I play in the editor, the script try to download the asset, because that’s impossible due to changed name, it drops an error “Resolving host timed out: nemdrive.com, no problem with this and works as expected.

Then I placed a button to retry the download when this happens, and here is the problem, when I press the button the player stops and drops this error:

Failed to load asset bundle
UnityEngine.WWW:get_assetBundle()

As far as I know, it is trying to extract the assets from the download (download is my var name for WWW object), but the download did not completed, even it must be null because the file could not be downloaded, What’s happening here?. It seems that after first attempt to make the download it thinks there is a download already in place and tries to extract something.

I tried in every way possible, any code combination and searched in every Unity related sites for an answer but I could’t find any clue.

And some weird things I saw:

1- When you make an attemto to download with the WWW class, the errors come after the download is made, and during the download progress the error is null, so you don’t know if there is a problem or not.
2- That means that, even when the download is impossible, after several seconds download.isDone goes truth.
3- Even download.progress equals to 1.

How the hell isDone can be truth and progress can be 1 if the download is not possible?

How can I tell the system that there is nothing downloaded to retry and avoid that the script tries to extract assets from the empty download?

In the retry button I used all kinds of stuff:

download.Dispose();
download = null;

but I saw no difference with this. And of course, in the InstantiateResource.js from the AssetBundle example, the progress is shown “if (download.error == null)”, but that means nothing because the error comes later.

This is very annoying and a big problem for me, or maybe I missed something. Please help.

The process to get there is rather easy:

  1. yield the www object and wait until its done (using isdone is an option too, but if you just want to get the end result its an overkill)
  2. check if there is an error
  3. if not, check if the data object you wanted to read from it is != null

if 2 and 3 go through, then it was successfully downloaded, otherwise you had a download error and need to issue the download another time.

that isDone is true is correct, because the download operation finished. Be it that it finished with incorrect data, a http error page or a real error, that does not matter, all isDone tells you is that no further downloading is happening on this WWW object

Thank you dreamora, the problem is the error is dropped ramdomly, maybe half the times I retry download I get the download error as expected and the other half I get the “Failed to load asset bundle”.

I’m of course yielding the download and I check for errors when the download process is completed.

function StartDownload ()
{
	//download = new WWW ("http://www.toyotacoopertiresdesafioextremo.com/game/" + trackBundles[selectedTrack]);
	download = new WWW ("http://nemdrive.com/Works/coopertires/DkC_Test2/" + trackBundles[selectedTrack]);
	yield download;

	print(download.error);
	if (download.error == null)
		assetBundle = download.assetBundle;
	
	if (assetBundle != null)
	{
		go = assetBundle.mainAsset;
	}else{
		errorDescarga = true;
	}		
}

and Unity says the error is in:

if (download.error == null)
	assetBundle = download.assetBundle;

because the error some times is null and some not.

Which is correct and to be expected.

the error will only be != null if the connection to the webserver fails completely.
If indeed the connection worked but the transmitted data are incorrect, the error will remain 0 but the attempt to access the data on the WWW object will result in a null reference being in there instead of a valid object

hi just came to a similar issue, the correct way to check if the bundle has been downloaded without error should then be “if (download.error==null download.assetBundle!=null)” ?

Thats what I would recommend to use yes, but you can also use download.text.Contains(“xxxx”) to check for specific errors and alike if you want special handling (I went with the way you have there cause the error is unimportant until we know the bundle failed to load)

ok perfect, thank you :slight_smile:

Thanks, this helped me fix a similar stubborn problem with getting Twitter profile pics. A search of 100 Tweets would always show one or two red ? marks instead of the profile pic. I found the .assetBundle didn’t work for me, I’d rather just discard the invalid pictures because they were being loaded into a particle texture. This code worked fine for my needs - (www.error==null www.size >= 1 )

HELP PLEASE

https://answers.unity.com/questions/1489665/downloading-and-caching-assets-bundle-failed-to-re.html

Please do not resurrect old threads.

?what? this is old thread yeah but it had something similar to do with my thread, and mine its a new one and its happening now on 2017.3 version , im just looking for help not ressurecting anything, so you want to help or just want to give your human feelings to the thread itself?

You created a thread on Unity Answers you dont have to spam other threads.
Yes spam. You clearly typed all capitals as can be seen below.

It definitely does not give off a good impression. Sorry if youre offended but typing all capitals to a 5 year old thread is not a good start to a conversation.

EDIT:
Your own thread also does not seem to have much information which is probably why you have not received a response.

And your post are not spams? ok are trolling , nice trolling keep it up and thanks for your ignorance and the leaks of information and help that you got CLOSE THIS THREAD so i cant post back again … becouse if i can post its coz i can… so why i will not do it? why the button of post reply is here if we cant post here? Fix the webpage then.