Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by AlfAtUnity · Mar 04, 2015 at 07:04 PM · androidassetbundle

Load scene from asset bundle

I have asset bundle with single asset -> "Assets/scene.unity". I try to instantiate my scene on Android with Unity 5:

 string[] scenePath = bundle.GetAllScenePaths();
 Debug.Log(scenePath[0]); // -> "Assets/scene.unity"
 Object myScene = bundle.LoadAsset(scenePath[0]);
 if(myScene != null)
     Instantiate(myScene);

However, myScene is null. Can you please help?

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
6
Best Answer

Answer by pitimoi · Mar 05, 2015 at 02:36 AM

Hello !

Scenes are not used like normal assets inside an Assetbundle and are not Objects that you can instantiate.

The way you have to use a scene is the following :

 string[] scenePath = bundle.GetAllScenePaths();
 Debug.Log(scenePath[0]); // -> "Assets/scene.unity"
 SceneManager.LoadSceneAsync(System.IO.Path.GetFileNameWithoutExtension(scenePath[0]));
 

In fact, you don't even have to call GetAllScenePaths() to make it works. At the moment you use the www.assetbundle getter that give you your "bundle" variable, all scenes in it can be loaded with Application.LoadLevel() with their name.

Edit: updated with comments and new API.

Comment
Add comment · Show 6 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image AlfAtUnity · Mar 05, 2015 at 04:13 PM 0
Share

Thanks for your reply! But in my case this won't work (for some reason - on my device - Application.dataPath points to apk ins$$anonymous$$d of obb). So, if I use Application.LoadLevel() it will try to load it form apk. That's why I use asset bundles: read from obb manually, get byte[], construct asset bundle at runtime. Currently I load empty level and then populate it with prefabs. I thought that it could be easier to load level, but now it's clear that it's not possible. You saved me a lot of time! +1000 )

avatar image ninja_gear · May 19, 2016 at 07:08 PM 0
Share

Every time I attempt your method I get:

'Scene 'Assets/AssetBundles/levelToLoad.unity' (-1) couldn't be loaded because it has not been added to the build settings or the AssetBundle has not been loaded.'

I have tried to (yield return) LoadAllAssetsAsync, LoadSceneAsync, nothing works. I get the same answer, even after I add that scene to the Build Settings (which I thought that AssetBundles Side stepped this allowing people to add scenes dynamically through DLC after release.

avatar image Arcanafex · Jun 13, 2016 at 03:17 AM 2
Share

@ninja_gear

The call to load the scene needs to be just the bare scene name. Try something like:

  var async = Scene$$anonymous$$anager.LoadSceneAsync(System.IO.Path.GetFileNameWithoutExtension(scenePath[0]));
avatar image VisalDXP Arcanafex · Jul 26, 2016 at 02:57 PM 0
Share

Thanks @Arcanafex 's suggession works for me

avatar image MonkeyPuzzle · Jul 27, 2018 at 06:47 PM 0
Share

Could you load all of the assets of a scene? Terrain, models, etc. as an asset bundle and destroy the current 'level' assets keeping the player?

avatar image RaviVohra · Dec 18, 2019 at 08:15 AM 0
Share

i uploaded my whole game in web as asset bundle , now i just want to load a scene inside scene folder how can i locate and open my scene . And can i delete all my asset from inside the unity ,and the only thing left is assetDownloader script.

avatar image
0

Answer by junedmmn · Sep 17, 2018 at 03:23 PM

Application.LoadLevel() is obsolete. Using SceneManager.LoadSceneAsync() works. use this:

 string[] scenePath = bundle.GetAllScenePaths(); 
 Debug.Log(scenePath[0]);
 SceneManager.LoadSceneAsync(System.IO.Path.GetFileNameWithoutExtension(scenePath[0]));
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

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

Answers Answers and Comments

26 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

CharacterCustomization AssetBundles 1 Answer

Android Plugin and Asset Bundles 0 Answers

how to delete specific files from cache? 3 Answers

Which way is better to handle AssetBundle management 2 Answers

3D model is not showing in Android 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges