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 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 everything 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(Caching.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 this. 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 caching - 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

sorry but i disagree here, bcoz if i call LoadCurrentLevel regardless of whether the bundle is cached or not, then i will get the error that you cannot download an already cached bundle when i reopen the leven again without quitting the game as in that case the bundle is already loaded.

avatar image joelmgallant · Jan 17, 2013 at 04:40 PM 0
Share

Right, you'll only want to do the bundle load part at the very beginning (each time the application is launched) - every time you want to load a level after that Application.LoadLevel() should be enough!

avatar image crazy_boy_02 · Jan 17, 2013 at 04:45 PM 0
Share

yes i figured that after 5 hours...it's done now..anyways thanks for your reply ...

avatar image joelmgallant · Jan 17, 2013 at 04:50 PM 0
Share

Glad to hear it! :)

avatar image hawkeye_01 · Mar 01, 2013 at 07:18 AM 0
Share

@ crazy_boy_02: how did you solved this problem? I m having exactly same problem as urs.

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

perfect!!!

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 Caching.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 this 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.

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

How to load a scene from an asset bundle in unity 5? 1 Answer

Changing Scenes using Unity5 AssetBundle 1 Answer

Ambient etc. are lost when scene is build to AssetBundle. Is this a bug? 0 Answers

How to perform Unloading Scene AssetBundles instead of unloading assetbundles having gameobjects in it? 2 Answers

Asset Bundle starts loaded 0 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