Problem in loading Scene from Asset Bundle...

Hi All,

I am trying to load a scene from an AssetBundle(unity web player)the bundle is also cached.

When i run it for the first time everything runs absolutely perfect and the new scene is loaded, but when i quit the game once and run the build again it gives the error

the level (level name) could not be loaded as it has not been added to the build settings.

Here is the code

Code to Build Asset Bundle

//Creating Asset Bundles For web Player
@MenuItem ("Assets/Build AssetBundle Factory Area %u")
static function CreateSceneBundle1(){
    
	// list of the levels to be streamed 
	var levels : String[] = ["Assets/1-Scenes/AbandonedDay.unity",
								"Assets/1-Scenes/AbandonedSunset.unity",
 								"Assets/1-Scenes/AbandonedNight.unity"];

	var path = EditorUtility.SaveFilePanel ("Save Resource", "", "factoryarea", "unity3d");
	
	if (path.Length != 0)
	{
		BuildPipeline.BuildStreamedSceneAssetBundle( levels,path, BuildTarget.WebPlayer);
	}
}

code to load level from assetbundle

void Update()
{
		if(Input.GetButtonDown("Jump"))
		{
			if(CheckBundleCacheStatus(url))
			{
			        Debug.Log("Level already Cached");
				Application.LoadLevel("AbandonedDay");
			}
			else
			{
				StartCoroutine(LoadCurrentLevel(url));
			}
		}
	}

bool CheckBundleCacheStatus(string url)
{
	if(Caching.IsVersionCached(url,1))
		return true;
	else
	        return false;
}

IEnumerator LoadCurrentLevel(string url)
{
	bundleWWW = WWW.LoadFromCacheOrDownload(url,1);
	yield return bundleWWW;
	if (bundleWWW.error != null)
	{
		Debug.Log("WWW download had an error:" + bundleWWW.error);
	}
	else
	{
		AssetBundle myLoadedAssetBundle = bundleWWW.assetBundle;
		myLoadedAssetBundle.LoadAll();
		Debug.Log("Download Completed now load level");
		Application.LoadLevel("AbandonedDay");
	}
}

can anyone help me with this. Thanks

It looks like the problem here is related to the caching - not how it works, but what it does & doesn’t cache.

What it will cache is the bundle itself - you’ve got that portion right, and can avoid downloading it again. However, just because the bundle is cached, you still have to load the assets from it again!

Fortunately, you’ve already got both sides of the download covered with the:

bundleWWW = WWW.LoadFromCacheOrDownload(url,1);

So, ultimately, you can still do the cache check, but your LoadCurrentLevel function should be called regardless of whether the bundle is cached or not.

It’s really the

       AssetBundle myLoadedAssetBundle = bundleWWW.assetBundle;
       myLoadedAssetBundle.LoadAll();

portion that’s going to make the level available to Application.LoadLevel.

Well, for unloading scene you can make asset bundle static public and then call bundle.Unload(false) in Start() of another scene that’s loaded.

I was getting the same problem where unity was throwing error “Cannot load cached AssetBundle. A file of the same name is already loaded from another AssetBundle”. I was loading asset bundles at different stages of level but when I try to restart the level and try to load the asset bundle again I got the same error stated above. Then I tried saving the asset bundles in a list and trying to clear the list at level restart but that doesn’t solved the problem. I even tried Caching.CleanCache() to remove any data from the memory but no use.
I was saving the assets bundles on the disk after downloading and loading them again from the disk after level load.

Solution:
private IEnumerator LoadAssetFromFile(string _name)
{
print(“Came inside LoadAssetFromFile :” + _name);
WWW www= new WWW(string.Concat(“file:///”, Application.dataPath, “/”, _name +“.unity3d”));//(m_savePath + _name);
//WWW www= new WWW(string.Concat(Application.dataPath, “/”, _name));//(m_savePath + _name);

	yield return www;

	if(www.error == null)
	{
		//m_bundle =  www.assetBundle;
		AssetBundle bundle =  www.assetBundle;
		www.Dispose();
		www = null;
		string path = m_savePath + _name;
		//object [] obj = m_bundle.LoadAll();
		//for(int i=0; i< obj.Length; i++)
		//{
			//print ("Obj :"+ i +" " + obj*.ToString());*
  •   	//}*
    
  •   	bundle.LoadAll();*
    
  •   	print ("AssetBundle is :" + bundle.mainAsset);*
    
  •   	print("============> " + path);*
    
  •   	GameObject _go =  (GameObject)Instantiate(bundle.mainAsset);*
    
  •   	bundle.Unload(false);*
    
  •   }*
    
  •   else*
    
  •   {*
    
  •   	return false;*
    
  •   }	*
    
  • }*
    using bundle.Unload(false) after instantiating the gameObject have done the trick. Not sure wether its mandatory to unload the bundle after you have instantiated it. But this has solved my problem.

PLEASE ANSWER THIS :-

if i made a game and exported all its assets inside asset builder and uploaded to web , than can i delete all my asset from the game as i am going to download all asset from net later and run a scene from that assets .