Loading scene from assetbundle (url)

I want to load the scene using www but it fails to download and shows a null. I’m not sure why it doesn’t download.

using UnityEngine;
using System.Collections;
using AssetBundles;

public class loadingscene : MonoBehaviour
	public string sceneAssetBundle;
	public string sceneName;
	public string url;
	// Use this for initialization
	IEnumerator Start ()
		yield return StartCoroutine(Initialize() );
		// Load level.
		yield return StartCoroutine(InitializeLevelAsync (sceneName, true) );
	// Initialize the downloading url and AssetBundleManifest object.
	protected IEnumerator Initialize()
		// Don't destroy this gameObject as we depend on it to run the loading script.
		// With this code, when in-editor or using a development builds: Always use the AssetBundle Server
		// (This is very dependent on the production workflow of the project. 
		// 	Another approach would be to make this configurable in the standalone player.)
		//	AssetBundleManager.SetDevelopmentAssetBundleServer ();
		// Use the following code if AssetBundles are embedded in the project for example via StreamingAssets folder etc:
		AssetBundleManager.SetSourceAssetBundleURL(Application.dataPath + "/");
		// Or customize the URL based on your deployment or configuration
		// Initialize AssetBundleManifest which loads the AssetBundleManifest object.
		var request = AssetBundleManager.Initialize();
		if (request != null)
			yield return StartCoroutine(request);
	protected IEnumerator InitializeLevelAsync (string levelName, bool isAdditive)
		WWW www = WWW.LoadFromCacheOrDownload (url, 1);
		yield return www;
		if (www.error != null) {
			print ("WWW donwload had an error : " + url + " " + www.error);
		AssetBundle bundle = www.assetBundle;

		// This is simply to get the elapsed time for this phase of AssetLoading.
		float startTime = Time.realtimeSinceStartup;
		// Load level from assetBundle.
		AssetBundleLoadOperation request = AssetBundleManager.LoadLevelAsync(sceneAssetBundle, levelName, isAdditive);
		if (request == null)
			yield break;
		yield return StartCoroutine(request);
		// Calculate and display the elapsed time.
		float elapsedTime = Time.realtimeSinceStartup - startTime;
		Debug.Log("Finished loading scene " + levelName + " in " + elapsedTime + " seconds" );
		// Frees the memory from the web stream

If you want to “download” the asset Bundle from the StreamingAssets folder you need to change

AssetBundleManager.SetSourceAssetBundleURL(Application.dataPath + "/");

to something like


More infos are here, here and here.

However if you want to download the Asset Bundles from the web you need to remove the / from line 36 of your posted code.




Adapt the link and comment out the local call

AssetBundleManager.SetSourceAssetBundleURL(Application.dataPath + "/");

before, otherwise it looks up the local path instead of the url.