Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Unity 5 AssetBundles have me scratching my head

Discussion in 'Editor & General Support' started by root8888, Mar 27, 2015.

  1. root8888

    root8888

    Joined:
    Jul 25, 2013
    Posts:
    26
    Everything is going great in my current web player game, except that I'm creating just too much content. A great problem to have! All of the 100+ different levels in my game each have their own scene. Adding them and organizing them in the build settings is tedious and it seems crazy to load every single level every time someone wants to play one. All I want to do is have a scene in a file and be able to load and unload it with a command. It seems like there should be a single line that loads an external scene just like an internal one. For example, instead of using:

    Code (csharp):
    1. Application.LoadLevel ("scene01");
    Use something like this:

    Code (csharp):
    1. WWW.LoadLevel ("./levels/level0001");
    So, that led me to Google, which led me to AssetBundles, which led me to questions and problems, which led me here.

    General questions:
    • I see they added an Asset Labels tab to the editor, but I have to add a script to my project to actually build the bundles. If Asset Bundles are a default part of Unity 5, why isn't that functionality in the main window already?
    • Do I really have to build every single asset every time? It seems like I should be able to click a button next to asset name in the Asset Labels tab to build that single asset.
    • I've built and uploaded my AssetBundles to the web server. Why do I get the error "Exception: WWW download had an error:Invalid Unity Web File (Decompression Failure).", when I try to load them? This is my code:
    Code (csharp):
    1.  
    2.     IEnumerator GetAssetTest () {
    3.         // Start a download of the given URL
    4.        
    5.         string AssetName = "level0001";
    6.        
    7.         using (WWW www = new WWW("http://www.servername.com/gamename/AssetBundles/level0001")) {
    8.             yield return www;
    9.             if (www.error != null)
    10.                 throw new Exception("WWW download had an error:" + www.error);
    11.             AssetBundle bundle = www.assetBundle;
    12.             if (AssetName == "")
    13.                 Instantiate(bundle.mainAsset);
    14.             else
    15.                 Instantiate(bundle.LoadAsset(AssetName));
    16.             // Unload the AssetBundles compressed contents to conserve memory
    17.             bundle.Unload(false);
    18.            
    19.         } // memory is freed from the web stream (www.Dispose() gets called implicitly)
    20.     }
    21.  
    I must be missing a step. Does anyone have a simple tutorial on how to do what I am looking for? It seems like External Scene Loader would be a great thing for someone to make a few bucks with in the Asset Store. Feel free anyone, I'll buy it! :)

    Once I actually get the scene imported, how do I get rid of it? Can I just unload the AssetBundle and load another one? Do I have to keep track and Destroy() all the objects?
     
  2. rakkarage

    rakkarage

    Joined:
    Feb 3, 2014
    Posts:
    683
    root8888 likes this.
  3. root8888

    root8888

    Joined:
    Jul 25, 2013
    Posts:
    26
    Well, that certainly looks awesome, but it sounds like it is only loading internal scenes. I've already got that bit worked out. I just need to load an external scene. Thanks for the link!
     
  4. root8888

    root8888

    Joined:
    Jul 25, 2013
    Posts:
    26
    This feels like something that would be a very common request, but I can't seem to find an easy solution. Isn't putting each game level in its own scene common practice? Wouldn't loading scenes from an external file be the most common reason to load anything from an external file?

    Am I looking at this whole thing the wrong way? Maybe there is a better approach entirely? I have seen people suggest setting up all the assets via a text file with JSON, but that doesn't seem like a good idea. I don't want to keep objects from 1000 different level in the main web player .unity3d file.
     
  5. sbfhhh

    sbfhhh

    Joined:
    May 9, 2014
    Posts:
    3
    bump! Ihave same problem
     
    root8888 likes this.