- Home /
Best way to determine WWW timeout/404/etc.?
I need to load a random number of textures at runtime. They may or may not exist at the given URL, if the server is even up. Some of them might be local ("file:///...."). Eventually, I need to know when to give up looking for them.
Does the WWW object have a way of doing this? The .error member? Syntax?
Answer by Mike 3 · Jan 31, 2011 at 04:31 AM
Yep, the .error property is exactly what you want
if (www.error != null)
{
//you couldn't download for some reason. www.error will be the string saying why
}
So, to be sure, in the cases I worry about, isDone will never be true, but eventually error will be non-null? Or would isDone go true with the error too?
@DaveA: isDone will be true when it's done, regardless of errors.
Answer by cwodarcz · Feb 23, 2012 at 11:14 PM
If I can follow up on this, it seems like the 404 error is actually not in the error attribute, but in the text attribute... I've had no problems with actually getting the WWW code to download my files and accessing my data, but when testing rainy day scenarios, such as file not existing, etc, the isDone property seems successfully set to true, but the error property is null... after spending some time stripping down my code to the simple use of WWW on its own, I found the actual 404 not found error string was in the text property. I noticed another post on here that someone had the same problem... is this a known issue with a potential resolution, otherwise what's a good simple way to detect this error, as the .NET XML parser seems to throw an exception when trying to parse this information. If anyone would like more information, I can post it...
Here is what I'm seeing in my Unity Web Log:
Success somehow...:
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html>
<head>
<title>404 Not Found</title>
</head>
<body>
<h1>Not Found</h1>
<p>The requested URL /sandboxes/applets/bootstrap/assetdownloads.xml was not found on this server.</p>
</body>
</html>
from accessing WWW.text's property.
I'd hate to have to write a 'screen scraper' to detect 404's in text, because some servers are configured to put up cutsy stuff. I would think the headers should contain the 404 status, and those are available, if poorly documented.
Your answer
Follow this Question
Related Questions
Load texture on disabled GameObject 1 Answer
loading different image links into a list 0 Answers
WWW.texture with a wildcard in the URL 1 Answer
How to assign texture from url 1 Answer