- Home /
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);
}
}
}
I put the complete scene in a bundle via:
using UnityEngine;
using UnityEditor;
public class ExportSceneAssetBundle {
[$$anonymous$$enuItem("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...
Answer by whydoidoit · Jun 20, 2013 at 12:51 AM
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).
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...
$$anonymous$$gestions? I search meanwhile on the forum
thanks
Yeah you only have to do it once and keep a reference to the bundle
Your answer
Follow this Question
Related Questions
Memory Locking While Loading Issue 0 Answers
Assets Bundle... in Pro? 2 Answers
Accessing an already loaded Asset Bundle 1 Answer
WWW::Dispose doesn't work 1 Answer