0

I have made asset bundle of a scene like this

    [MenuItem("MFKJ/BuildSceneAsset")]
    static void myBuild() {

        string[] levels = { "Assets/Scene/Scene2.unity" };
        string v = BuildPipeline.BuildStreamedSceneAssetBundle(levels, "Assets/AssetBundles/Streamed-Level2.unity3d", BuildTarget.StandaloneWindows);
        Debug.Log(v);
        //"Streamed-Level1.unity3d"
        //BuildPipeline.BuildStreamedSceneAssetBundle(levels, "Streamed-Level1.unity3d", BuildTarget.StandaloneWindows64);

}

This has made a .unity3d assetbundle file in specified folder. Now on run time i am loading the scene from asset bundle form another scene using this code.

public string url;
    // Use this for initialization
    void Start () {

        url = "file://" + Application.dataPath + "/AssetBundles/Streamed-Level2.unity3d";
        Debug.Log("scene load url : " + url);
        StartCoroutine(LoadSceneBundle());
    }

    // Update is called once per frame
    void Update () {

    }

    public IEnumerator LoadSceneBundle() { 
        using (WWW www = WWW.LoadFromCacheOrDownload(url,1)){
            yield return www;
            if (www.error != null) {
                throw new Exception("WWW donwload had an error : " + url + " " + www.error);
                //Debug.Log("");
            }
            AssetBundle ab = www.assetBundle;
            Debug.Log(www.assetBundle.mainAsset);

            //GameObject gm = ab.mainAsset as GameObject;
            //Debug.Log("Scene2PassValue : " + gm.name);
            //Instantiate(gm);
            //ab.LoadAll(typeof(GameObject));
            ab.LoadAll();

            ab.Unload(false);
        }
    }

but unfortunately this is not loading the streamed scene or any asset of streamed scene from asset bundle. what i am missing?

Fredrik Widerberg
  • 3,068
  • 10
  • 30
  • 42
Muhammad Faizan Khan
  • 10,013
  • 18
  • 97
  • 186
  • how do you know the assets aren't getting downloaded? You don't seem to be making any calls to Application.LoadLevel – Radu Diță Nov 02 '15 at 17:50
  • so i have to load level also? yes i have done but why LoadAll is not loading the scene – Muhammad Faizan Khan Nov 03 '15 at 04:13
  • and the problem is also that build player is not loading the scene – Muhammad Faizan Khan Nov 03 '15 at 05:06
  • yes, you need to make a call to Application.LoadLevel: http://docs.unity3d.com/ScriptReference/BuildPipeline.BuildStreamedSceneAssetBundle.html . Are you getting any errors? How do you know that the objects are not loaded, they won't appear as soon as you load the asset bundle, this is because you could load multiple ones at the same time. – Radu Diță Nov 03 '15 at 09:27
  • the scene almost working but some time dont load while after building it is completely not working. m pulling my hair – Muhammad Faizan Khan Nov 03 '15 at 11:10

0 Answers0