- Home /
Question by
Siccity · Jun 28, 2017 at 02:57 PM ·
scripting problemassetbundlescene-loadingscenesassetbundles
Load a scene from AssetBundle
I've been googling all day for a solution to this problem.
How do you load a scene through an asset bundle? Loading the scene directly after getting www.AssetBundle gives me error couldn't be loaded because it has not been added to the build settings or the AssetBundle has not been loaded.
Any attempt at loading the assetbundle (eg. www.AssetBundle.LoadAllAssets()); gives me error InvalidOperationException: This method cannot be used on a streamed scene AssetBundle.
This is my script
//Download asset bundle
WWW bundleWWW = WWW.LoadFromCacheOrDownload(sceneURL, 1);
yield return bundleWWW;
assetBundle = bundleWWW.assetBundle;
if (assetBundle.isStreamedSceneAssetBundle) {
string[] scenePaths = assetBundle.GetAllScenePaths();
string sceneName = System.IO.Path.GetFileNameWithoutExtension(scenePaths[0]);
assetBundle.LoadAllAssets(); //InvalidOperationException: This method cannot be used on a streamed scene AssetBundle.
SceneManager.LoadScene(sceneName); //couldn't be loaded because it has not been added to the build settings or the AssetBundle has not been loaded.
}
Comment
Best Answer
Answer by Siccity · Jun 29, 2017 at 08:51 AM
Found the solution. I had a dot (.) in my scene file name. Apparently this isn't supported.
The final working code is:
//Download asset bundle
WWW bundleWWW = WWW.LoadFromCacheOrDownload(sceneURL, 1);
yield return bundleWWW;
assetBundle = bundleWWW.assetBundle;
if (assetBundle.isStreamedSceneAssetBundle) {
string[] scenePaths = assetBundle.GetAllScenePaths();
string sceneName = System.IO.Path.GetFileNameWithoutExtension(scenePaths[0]);
SceneManager.LoadScene(sceneName);
}