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
0
Question by IntDev · Apr 17, 2015 at 11:06 AM · sceneassetbundleloadlevel

Load Scene in AssetBundle and Unload

I load a scene in my AssetBundle like this:

 IEnumerator AsyncLoad ()
 {
     using (var www = new WWW("file://" + Application.dataPath + "/AssetBundles/scenes"))
     {
         yield return www;
 
         var bundle = www.assetBundle;
 
         Application.LoadLevel("Scene1");
 
         bundle.Unload(false);
     }
 }

The problem is sometimes Application.LoadLevel("Scene1"); works fine and sometimes Scene1 is empty. What's wrong here?

Side note: I noticed LoadLevel destroys the current scene before loading, so the lines after LoadLevel are not being executed (since the script was destroyed). As I need to unload the asset bundle in order to use it again another time, what's the solution?

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

4 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by alexeyzakharov · Jul 20, 2015 at 12:34 PM

Actual problem here is that Application.LoadLevel only guaranties to finish loading level next frame (documentation will be updated). Thus Unload() call might unload data before it is loaded by LoadLevel operation.

The simplest workaround in your case is to use async operation:

 var asyncOp = Application.LoadLevelAsync("Scene1");
 yield return asyncOp;
 
 bundle.Unload(false);

Also take a look at Vincent's AssetBundle Demo project where AssetBundle loading framework is provided.

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
avatar image
1

Answer by djoshi · Jun 12, 2017 at 06:52 AM

For unloading scene you can make asset bundle static public and then call bundle.Unload(false) in Start() of another scene that's loaded.

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
avatar image
0

Answer by Ekta-Mehta-D · Apr 17, 2015 at 11:31 AM

Hii..

For Loading scene first you need to load all assets from the server.

and for using another time u need to use loadfromcacheordownload.

Have a look at this : Similar problem

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
avatar image
0

Answer by Wothanar · May 10, 2018 at 01:43 AM

its a unity bug, why i cant save a scene as a variable ? why it happend this! is no sense! its so anoying ! unity come one cache system sucks , the scenes cant being unloaded coz they go away , i dont want people load async level it will change my entire system coz just another unity bug? seriously?

//// i use AssetBundle.UnloadAllAssets(); and i record the scenes asset bundles into a variable... if (bundleMaps [0] == null) {

and its null but the damn bundle says that its loaded? whaaaaaaat? and i used the unload stuff on the beginning its a non sense bug! there is no way this error its a damn bug ... coz it happend when who knows what happend its just come from no where some times works fine my code but some times its just stop all the entire update process of assets bundles and my app become freeze and i cant act as a respond of HOW CAN I RESTART THE APP IF THIS ERROR COME ITS THERE ANY WAY FOR THIS? COZ I DONT WANT TO CHANGE MY ENTIRE GAME SYSTEM JUST FOR THIS ERROR THAT COME LIKE FROM THE NO WHERE IN A RANDOM SITUATION ITS JUST SERIOUSLY A DAMN CURSE BUG!.

 while (!Caching.ready)
             yield return null;
         if (bundleMaps [0] == null) {
         using (clonewww = WWW.LoadFromCacheOrDownload ("http://www.privatelink.com/mapspack0", MapsPackV [0])) {
             showdata = true;
             yield return clonewww;
             if (clonewww.error != null) {
                 Debug.Log ("WWW download had an error:" + clonewww.error);
                 DebuGText.text += "WWW download had an error:" + clonewww.error + "\n";
                 GameObject tempobj = GameObject.Find ("RADIOPLAYEROBJ");
                 Destroy (tempobj);
                 SceneManager.LoadScene (0);
                 Destroy (transform.gameObject);
             }
             showdata = false;
             totalsizedownloaded += clonewww.bytesDownloaded;
             AssetBundle bundle = clonewww.assetBundle; 
             bundleMaps [0] = bundle;
             while (bundle == null) {
                 yield return null;
             }
             //AssetBundleRequest assetBundleRequest = bundle.LoadAllAssetsAsync();
             displaytext.text = "MAPS PACK 0 Loaded!";
             GetAllScenePathsArray = bundle.GetAllScenePaths ();
             foreach (string o in GetAllScenePathsArray) {
                 Debug.Log (o.ToString ());
                 DebuGText.text += o.ToString () + "\n";
             }
             foreach (string ma in GetAllScenePathsArray) {
                 string temps = Path.GetFileNameWithoutExtension (ma);
                 DLCMAPS.Add (temps);
             }
             
             // Unload the AssetBundles compressed contents to conserve memory
             //bundle.Unload(false); 
             //END LOAD MAP
             //Go final check here if all its right we display login screen.
 
         }

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

22 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

Related Questions

Scene Asset Bundle - LoadLevelAdditive and OnLevelWasLoaded 1 Answer

Load scene on button press 4 Answers

load .unity3d with resource, scene and executable script 0 Answers

editor load android scene assetbundle error 1 Answer

Application.LoadLevel Strange Problem 2 Answers


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