Search Unity

Basic Asset Bundle tutorial?

Discussion in 'Community Learning & Teaching' started by tool55, Mar 13, 2010.

  1. tool55

    tool55

    Joined:
    Jul 10, 2009
    Posts:
    334
    Hi Guys,

    Just wondering if there's a good tutorial on the basics of Asset Bundles. I downloaded the example Asset Bundle project, but am having trouble even opening it (though I'll figure it out eventually) and it comes with no documentation as far as I can tell.

    Thanks for the help.

    Regarding the example project, I'm getting an error message saying that I need to click on "download shared assets", then click on Lerpz. I'm not sure what this means. I have the Lerpz project on my computer, but click download where? Not sure what they're talking about. Thanks again. :roll:
     
  2. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    Sure you ran the asset bundle build scripts that come with it.
    it will "download" it right out of the own folder if you execute it in the editor.


    There is nothing magic about assetbundles. Simply put an asset bundle is just an "external, dynamically loadable resources folder" and you work exactly the same way with it.
     
  3. tgraupmann

    tgraupmann

    Joined:
    Sep 14, 2007
    Posts:
    828
    Sometimes asset bundles can cause agony.

    I wish the WWW response code was exposed. You can try and download an asset bundle and get a 404. You won't know the asset bundle is bad until you try to load the asset bundle property.

    It would be nice if we could check for a 200 response code, or check the bytes[] to see there wasn't an error.

    Sometimes you can't rely on just WWW.error
     
  4. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    On an error, WWW.error will expose it actually.
    otherwise WWW.data exposes the return of the server especially when it fails


    on the webbuild its just important to keep in mind that WWW is handled through the browser http networking so if the browser goes bogus, so will the webplayer
     
  5. tool55

    tool55

    Joined:
    Jul 10, 2009
    Posts:
    334
    Thanks, Dreamora. I'll look for the script you mentioned and run it. And thanks for the explanation. As always, you have a way of making things nice and simple.
     
  6. HeywoodFloyd

    HeywoodFloyd

    Joined:
    May 27, 2009
    Posts:
    16
    Which script is that?

    <Edit>Okay, finally figured it out: the script adds items to the "Assets" dropdown menu in the Unity editor. Selecting those items builds the asset bundles.</Edit>
     
  7. BillyT

    BillyT

    Joined:
    Sep 1, 2010
    Posts:
    28
    Can anyone provide more info on the steps required to get this example to work? I can see the options in the assets menu, but which one do I choose? And what do I have selected when I select the menu item? Where do I save the asset bundle? What should it be called?

    Thanks in advance
     
  8. Ostagar

    Ostagar

    Joined:
    Sep 29, 2010
    Posts:
    445
    tgraupmann is correct, at least I've seen this on Unity iPhone 1.7 and also a feature request which implies it's not limited to that version: http://feedback.unity3d.com/forums/...160-scripting-expose-http-status-in-www-class

    WWW.error is set for transport errors but not for 404 errors and other web server error codes. The WWW code in the Unity docs and Wiki assume if WWW.error is not set, the page loaded fine, and that's not always true. It's a good caveat to know about so you can do extra checking.

    Aye, there are usually other ways to check for an error, parsing the WWW.text being one of them.
     
  9. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    Well on one of the the two the error comes through, always.
    Either the connection itself failed, then its www.error that will tell you or the webserver returned a value in which case it wrote it down into the answer, which will push it through to you on www.text (or www.data prior U3) :)
    Keep in mind, WWW does not much more than you browser http connection would do and gets the same answers and provides the same reactions given you implement the parsing of data.

    www.error out of my view primarily / only happens if the data that came back was messed up and not even a text.
     
  10. Ostagar

    Ostagar

    Joined:
    Sep 29, 2010
    Posts:
    445
    Here's an example, where I downloaded the wrong page from kitcar.com via Unity 1.7:

    (a) WWW.error == null, so that check failed.
    (b) Regexp'ing for "404" in WWW.data also fails (and is risky since user data may contain "404")

    Sure, you and I can read this page and see it says "missing link", but writing code that regexps for (404 | missing | oops | not found) is only a probabilistic algorithm--you're hoping those terms don't conflict with user data, that the web server admin wasn't so clever as to find another way to say it, and that it's an English-based server. Other web-fetching tools expose status codes. They're the golden standard.

    (Of course, in most applications, you know the format of the file you're attempting to download, and can verify its integrity that way. That's what I'm currently doing in one application.)
     
  11. Ostagar

    Ostagar

    Joined:
    Sep 29, 2010
    Posts:
    445
  12. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    Downloading it twice is no problem. but you must make sure the first one is unloaded when you request the second WWW

    I personally would recommend to use a Dictionary<string,AssetBundle> to store all downloaded asset bundles and use the url as key there. this way you can check if you have the bundle and only download it if not. saves a lot of time and bandwidth
     
  13. tranvv

    tranvv

    Joined:
    Jan 26, 2012
    Posts:
    2
    steps to use the tutorial:

    download the assetbundle.zip file and unzip it
    double click the AssetBundles/Assets/Loader.unity to load the project
    select the menu option Assets > Auto Build Resource Files
    run the project
     
  14. dreammakersgroupAdmin

    dreammakersgroupAdmin

    Joined:
    Feb 13, 2012
    Posts:
    40
    yeeah. thanks tranvv .
    now i know how to run the sample
     
  15. Fehr

    Fehr

    Joined:
    Mar 3, 2011
    Posts:
    23
    AutomatedExportResources.js will generate the bundle.
     
    Last edited: Apr 27, 2012
  16. DDP

    DDP

    Joined:
    May 17, 2012
    Posts:
    15
  17. SimonDarksideJ

    SimonDarksideJ

    Joined:
    Jul 3, 2012
    Posts:
    1,689