Search Unity

How can I load a scene in an AsssetBundle

Discussion in 'Editor & General Support' started by bhinjlk, Jun 18, 2015.

  1. bhinjlk

    bhinjlk

    Joined:
    Dec 15, 2014
    Posts:
    10
    I have created an AssetBundle with one scene but I don't know how to load it with the new Asset bundle system?
    Is it right?

    using (WWW download = new WWW("AssetBundleName"))
    {
    yield return download;

    if (download.error != null)
    Debug.LogError("WWW download had an error:" + download.error);

    var bundle = download.assetBundle;
    }
    Application.LoadLevel("SceneName");
     
  2. Graham-Dunnett

    Graham-Dunnett

    Administrator

    Joined:
    Jun 2, 2009
    Posts:
    4,287
    Don't think AssetBundles support scenes. Use the asset bundle to store all the assets, and just have a scene in the project with no assets in it.
     
  3. BFS-Kyle

    BFS-Kyle

    Joined:
    Jun 12, 2013
    Posts:
    883
    Asset bundles can contain scenes (possibly only 1 scene per bundle, but definitely allows scenes).

    As for your code, it looks correct. The only problem is the URL being used in the WWW request - "AssetBundleName" is not a URL. "file:///some/path/to/file/AssetBundleName" is more along the lines of what you would want to use.

    Apart from that it should work fine (assuming you have created the asset bundle correctly and put it in the right place).
     
    bhinjlk likes this.
  4. Graham-Dunnett

    Graham-Dunnett

    Administrator

    Joined:
    Jun 2, 2009
    Posts:
    4,287
    Wow. I am such a beginner!