- Home /
Streamed Asset Bundle Help
Im trying to Load a set of streamed asset bundles i created at run time. However something seems to be missing from my code. Could someone please take a look?
//public void LoadLevelAdditively ()
void Start()
{
//optimize this later as a for loop or whatever
StreamedAssetBundlePathsList.Add(url + "Streamed-LOD0.unity3d");
StreamedAssetBundlePathsList.Add(url + "Streamed-LOD1.unity3d");
StreamedAssetBundlePathsList.Add(url + "Streamed-LOD2.unity3d");
StreamedAssetBundlePathsList.Add(url + "Streamed-LOD3.unity3d");
StreamedAssetBundlePathsList.Add(url + "Streamed-LOD4.unity3d");
StreamedAssetBundlePathsList.Add(url + "Streamed-LOD5.unity3d");
//Loop through the list and download the compressed asset bundles from the web server,
//If the asset bundle was already downloaded and cached for any reason UNITY will skip this process
foreach(string StreamedAssetBundle in StreamedAssetBundlePathsList)
{
var AssetBundleDownload = WWW.LoadFromCacheOrDownload(StreamedAssetBundle,5);
//verify download
if(AssetBundleDownload.error != null)
{
Debug.LogError (AssetBundleDownload.error);
return;
}
//Load the current Asset Bundle into memory
var bundle = AssetBundleDownload.assetBundle.name;
//Additively Load the level into the scene
Application.LoadLevelAdditive("CityLOD" + StreamedAssetBundlePathsList.IndexOf(StreamedAssetBundle)); //<--LOD(int) refers to the scene name
}
}
The streamed asset bundles wont load into the scene, it just freezes and then crashes the web player
I would try to reproduce the problem with the simplest setup you can manage -- think of empty scenes, scenes with only one cube object, cutting out your looped WWW loads, loading via the file:// protocol from your developer machine, and so on. None of these suggestions will necessarily fix the problem, but they might help you narrow down what exactly is (or isn't) going awry.
I don't see where you're yielding on the download. You set up a WWW, but then try to access it immediately after - WWW calls don't return immediately, or block the execution until they return - they run asynchronously. Try running a coroutine and yielding the download.
Julien, That makes since, Im curious on how to yield until after the download is complete,
So do I put the actual WWW call in a coroutine and return to the foreach loop after its finished?
Answer by Julien-Lynge · Jul 24, 2012 at 08:37 PM
Answer: See the comment string. In a nutshell, it's necessary to yield AssetBundle downloads before trying to load them.