x


AssetBundles, not working ... "not been added to the build settings"

Hi guys,

i'm pretty new to unity. I have a few big landscape scenes (all in different projects) i'd like to load these dynamically in one unity game (pc/mac). I created seperate assetBundles from them.

So in my first landscape scene when u enter a door, it loads another scene. The script in the bottom is attached to that door. When i run it it gives the error: "Level: 'Ename_test.unity' (-1) couldn't be loaded because it had not been added to the build settings."

I've been looking on this forum for hours, but nothing solved this, although a lot of the same topics :/ Anyone knows a solution? thanks!

code:

using System;
using UnityEngine;
using System.Collections;

public class CachingLoadExample : MonoBehaviour {
    public string BundleURL;
    public string AssetName;
    public int version;

    void OnTriggerEnter(Collider other)
    {
        StartCoroutine (DownloadAndCache());
    }

    IEnumerator DownloadAndCache (){
        // Wait for the Caching system to be ready
        while (!Caching.ready)
            yield return null;

        // Load the AssetBundle file from Cache if it exists with the same version or download and store it in the cache
        using(WWW www = WWW.LoadFromCacheOrDownload (BundleURL, version)){
            yield return www;

            if (www.error != null)
                throw new Exception("WWW download had an error:" + www.error);
            AssetBundle bundle = www.assetBundle;
            bundle.LoadAll();

            Application.LoadLevel(AssetName);
        }
    }
}
more ▼

asked Jun 19, 2013 at 09:49 AM

MisterGasman gravatar image

MisterGasman
31 9 6 7

And how do you create the bundle?

Jun 19, 2013 at 10:26 AM whydoidoit

I put the complete scene in a bundle via:

using UnityEngine;
using UnityEditor;

public class ExportSceneAssetBundle {

    [MenuItem("Assets/Build SceneAssetBundle (full scene export)")]
    static void ExportResourceNoTrack () {

        // Bring up load panel
        string[] level = new string[]{EditorUtility.OpenFilePanel("Load scene", "", "unity")};


        if (level.Length != 0) {
            // Bring up save panel
            string export = EditorUtility.SaveFilePanel("Save scene Asset", "", "scene Asset", "unity3D");

            if (export.Length != 0) {
                //build assetBundle from scene
                BuildPipeline.BuildStreamedSceneAssetBundle(level, export, BuildTarget.StandaloneWindows64);
            }
        }
    }
}

The game loads the assetBundle (seems to), but when i use the loadLevel function it gives an error...

Jun 19, 2013 at 05:33 PM MisterGasman
(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

Ok so with a stream scene asset bundle you don't do bundle.LoadAll - you just take the reference to it from the WWW.

Secondly you need to open the scene with its name - not it's file name, just the scene name part of it (like you would if it was added to the build).

more ▼

answered Jun 20, 2013 at 12:51 AM

whydoidoit gravatar image

whydoidoit
53.3k 59 74 204

Ok thanks sir! It seems to work now. The scene from another project loads fine.

Now the problem is when the first scene loads again it got the following error:

"Exception: WWW download had an error:Cannot load cached AssetBundle. A file of the same name is already loaded from another AssetBundle."

When i add this "bundle.Unload(false);" under the LoadLevel the second scene is complete black, no polys or textures, nothing...

Suggestions? I search meanwhile on the forum

thanks

Jun 20, 2013 at 09:14 AM MisterGasman

Yeah you only have to do it once and keep a reference to the bundle

Jun 20, 2013 at 02:13 PM whydoidoit
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x669
x565
x30

asked: Jun 19, 2013 at 09:49 AM

Seen: 1234 times

Last Updated: Jun 20, 2013 at 02:13 PM