- Home /
Why is my AssetBundle causing "Exception: WWW download had an error:Invalid Unity Web File"
Everything is going great in my current web player game, except that I'm creating just too much content. A great problem to have! All of the 100+ different levels in my game each have their own scene. Adding them and organizing them in the build settings is tedious and it seems crazy to load every single level every time someone wants to play one. All I want to do is have a scene in a separate file and be able to load and unload it with a command. It seems like there should be a single line that loads an external scene just like an internal one. For example, instead of using:
Application.LoadLevel ("scene01");
Use something like this:
WWW.LoadLevel ("./levels/level0001");
So, that led me to Google, which led me to AssetBundles, which led me to questions and problems, which led me here.
I've built and uploaded my AssetBundles to the web server. Why do I get the error "Exception: WWW download had an error:Invalid Unity Web File (Decompression Failure).", when I try to load them? This is my code: [code] IEnumerator GetAssetTest () { // Start a download of the given URL
string AssetName = "level0001";
using (WWW www = new WWW("http://www.servername.com/gamename/AssetBundles/level0001")) {
yield return www;
if (www.error != null)
throw new Exception("WWW download had an error:" + www.error);
AssetBundle bundle = www.assetBundle;
if (AssetName == "")
Instantiate(bundle.mainAsset);
else
Instantiate(bundle.LoadAsset(AssetName));
// Unload the AssetBundles compressed contents to conserve memory
bundle.Unload(false);
} // memory is freed from the web stream (www.Dispose() gets called implicitly)
}
I must be missing a step. Does anyone have a simple tutorial on how to do what I am looking for? It seems like External Scene Loader would be a great thing for someone to make a few bucks with in the Asset Store. Feel free anyone, I'll buy it! :)
Once I actually get the scene imported, how do I get rid of it? Can I just unload the AssetBundle and load another one? Do I have to keep track and Destroy() all the objects?