• 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 crazy_boy_02 · Jan 17, 2013 at 08:20 AM · sceneassetbundlecaching

Problem in loading Scene from Asset Bundle...

Hi All,

I am trying to load a scene from an AssetBundle(unity web player)the bundle is also cached.

When i run it for the first time everyt$$anonymous$$ng runs absolutely perfect and the new scene is loaded, but when i quit the game once and run the build again it gives the error

the level (level name) could not be loaded as it has not been added to the build settings.

Here is the code

Code to Build Asset Bundle

 //Creating Asset Bundles For web Player
 @MenuItem ("Assets/Build AssetBundle Factory Area %u")
 static function CreateSceneBundle1(){
     
     // list of the levels to be streamed 
     var levels : String[] = ["Assets/1-Scenes/AbandonedDay.unity",
                                 "Assets/1-Scenes/AbandonedSunset.unity",
                                  "Assets/1-Scenes/AbandonedNight.unity"];
 
     var path = EditorUtility.SaveFilePanel ("Save Resource", "", "factoryarea", "unity3d");
     
     if (path.Length != 0)
     {
         BuildPipeline.BuildStreamedSceneAssetBundle( levels,path, BuildTarget.WebPlayer);
     }
 }


code to load level from assetbundle

 void Update()
 {
         if(Input.GetButtonDown("Jump"))
         {
             if(CheckBundleCacheStatus(url))
             {
                     Debug.Log("Level already Cached");
                 Application.LoadLevel("AbandonedDay");
             }
             else
             {
                 StartCoroutine(LoadCurrentLevel(url));
             }
         }
     }



 bool CheckBundleCacheStatus(string url)
 {
     if(Cac$$anonymous$$ng.IsVersionCached(url,1))
         return true;
     else
             return false;
 }


 IEnumerator LoadCurrentLevel(string url)
 {
     bundleWWW = WWW.LoadFromCacheOrDownload(url,1);
     yield return bundleWWW;
     if (bundleWWW.error != null)
     {
         Debug.Log("WWW download had an error:" + bundleWWW.error);
     }
     else
     {
         AssetBundle myLoadedAssetBundle = bundleWWW.assetBundle;
         myLoadedAssetBundle.LoadAll();
         Debug.Log("Download Completed now load level");
         Application.LoadLevel("AbandonedDay");
     }
 }


can anyone help me with t$$anonymous$$s. Thanks

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
Best Answer

Answer by joelmgallant · Jan 17, 2013 at 02:48 PM

It looks like the problem here is related to the cac$$anonymous$$ng - not how it works, but what it does & doesn't cache.

What it will cache is the bundle itself - you've got that portion right, and can avoid downloading it again. However, just because the bundle is cached, you still have to load the assets from it again!

Fortunately, you've already got both sides of the download covered with the:

 bundleWWW = WWW.LoadFromCacheOrDownload(url,1);


So, ultimately, you can still do the cache check, but your LoadCurrentLevel function should be called regardless of whether the bundle is cached or not.

It's really the

        AssetBundle myLoadedAssetBundle = bundleWWW.assetBundle;
        myLoadedAssetBundle.LoadAll();

portion that's going to make the level available to Application.LoadLevel.

Comment
Add comment · Show 8 · 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 crazy_boy_02 · Jan 17, 2013 at 04:37 PM 0
Share
avatar image joelmgallant · Jan 17, 2013 at 04:40 PM 0
Share
avatar image crazy_boy_02 · Jan 17, 2013 at 04:45 PM 0
Share
avatar image joelmgallant · Jan 17, 2013 at 04:50 PM 0
Share
avatar image hawkeye_01 · Mar 01, 2013 at 07:18 AM 0
Share
Show more comments
avatar image
1

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

Well, 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 · Show 1 · 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 Realite · May 02, 2018 at 02:52 PM 0
Share
avatar image
0

Answer by Jeet_9811 · May 22, 2014 at 07:22 AM

I was getting the same problem where unity was throwing error "Cannot load cached AssetBundle. A file of the same name is already loaded from another AssetBundle". I was loading asset bundles at different stages of level but when I try to restart the level and try to load the asset bundle again I got the same error stated above. Then I tried saving the asset bundles in a list and trying to clear the list at level restart but that doesn't solved the problem. I even tried Cac$$anonymous$$ng.CleanCache() to remove any data from the memory but no use. I was saving the assets bundles on the disk after downloading and loading them again from the disk after level load.

Solution: private IEnumerator LoadAssetFromFile(string _name) { print("Came inside LoadAssetFromFile :" + _name); WWW www= new WWW(string.Concat("file:///", Application.dataPath, "/", _name +".unity3d"));//(m_savePath + _name);
//WWW www= new WWW(string.Concat(Application.dataPath, "/", _name));//(m_savePath + _name);

     yield return www;

     if(www.error == null)
     {
         //m_bundle =  www.assetBundle;
         AssetBundle bundle =  www.assetBundle;
         www.Dispose();
         www = null;
         string path = m_savePath + _name;
         //object [] obj = m_bundle.LoadAll();
         //for(int i=0; i< obj.Length; i++)
         //{
             //print ("Obj :"+ i +" " + obj[i].ToString());
         //}
         bundle.LoadAll();
         print ("AssetBundle is :" + bundle.mainAsset);
         print("============> " + path);
         GameObject _go =  (GameObject)Instantiate(bundle.mainAsset);
         bundle.Unload(false);
     }
     else
     {
         return false;
     }    
 }
  using bundle.Unload(false) after instantiating the gameObject have done the trick.  Not sure wether its mandatory to unload the bundle after you have instantiated it.  But t$$anonymous$$s has solved my 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 RaviVohra · Dec 18, 2019 at 07:49 AM

PLEASE ANSWER THIS :-

if i made a game and exported all its assets inside asset builder and uploaded to web , than can i delete all my asset from the game as i am going to download all asset from net later and run a scene from that assets .

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

15 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

Related Questions

What things cause this message?The content was stopped because a... 3 Answers

Is it possible to create a scene from script and export it as an asset bundle? 0 Answers

Problem Building Streamed Scene Asset Bundle 2 Answers

Why does a scene loaded from an Asset Bundle returns empty string when getting its name? 0 Answers

AssetBundle.Unload(false) 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