Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice

New AssetBundle build system in Unity 5.0

Discussion in 'Unity 5 Pre-order Beta' started by Deleted User, Jan 28, 2015.

  1. Deleted User

    Deleted User

    Guest

    [EDIT]

    This post is now OBSOLETE!

    Please visit this page for up-to-date details.
    http://unity3d.com/learn/tutorials/...undles-and-assetbundle-manager?playlist=17117


    To discuss this topic, please use this thread:
    http://forum.unity3d.com/threads/the-assetbundle-manager-tutorial-q-a.354400/#post-2325204


    [/EDIT]

    In Unity 5.0, we have a new AssetBundle build system which is much more easier to use than the old one.

    Basic Introduction

    In the new AssetBundle build system, we provide:
    1. Simple UI to mark the assets into an AssetBundles, and keep the assets to AssetBundles mapping in the asset database.
      • You can find the UI at the bottom of the asset preview panel. It’s very simple, just try to use it.
      • The AssetBundle name will be stored in the meta file.
      • Also provide search filter in the search bar, you can type “b:” to search assets with given AssetBundle name.
      • Some restrictions:
        • Don’t allow mark one asset into multiple AssetBundles.
        • You can only set a relative path as the AssetBundle name.
        • You cannot mark scripts into AssetBundles.
        • You cannot mark scene asset and normal asset in a same AssetBundle.
    2. API to mark the asset into AssetBundle
      • You can use AssetImporter.assetBundleName to set the AssetBundle name.
    3. Simple APIs to build AssetBundles, BuildPipeline.BuildAssetBundles().These APIs are pretty simple, you only need to provide:
      • Output path for all the AssetBundles.
      • BuildAssetBundleOptions which will be described later.
      • BuildTarget which is same as before.
      • Also have one overloaded version to provide an array of AssetBundleBuild which contains one map from assets to AsssetBundles. This provides flexibility to you, you can set your mapping information by script and build from it. And this mapping information won’t break/replace the existed one in the asset database.
    4. APIs to manipulate AssetBundle names in the asset database
      • AssetDatabase.GetAllAssetBundleNames() which returns all the AssetBundle names in the asset database.
      • AssetDatabase.GetAssetPathsFromAssetBundle to return the asset paths marked in the given AssetBundle.
      • AssetDatabase.RemoveAssetBundleName() which removes a given AssetBundle name in the asset database.
      • AssetDatabase.GetUnusedAssetBundleNames() which returns the unused AssetBundle names.
      • AssetDatabase.RemoveUnusedAssetBundleNames() which removes all the unused AssetBundle names in the asset database.
      • AssetPostProcessor.OnPostprocessAssetbundleNameChanged callback which will be called if user change the AssetBundle name of an asset.
    5. BuildAssetBundleOptions
      • CollectDependencies & DeterministicAssetBundle are always enabled.
      • CompleteAssets is ingored as we always start from assets rather than objects, it should be complete by default.
      • ForceRebuildAssetBundle is added. Even there is no change to the assets, you can force rebuild the AssetBundles by setting this flag.
      • IngoreTypeTreeChanges is added. Even type tree changes, you can ignore the type tree changes with this flag.
      • DisableWriteTypeTree conflicts with IngoreTypeTreeChanges. You can't ignore type tree changes if you disable type tree.
    6. Manifest file. We generate the manifest file for every AssetBundle which contains the following information:
      • The manifest file is next to the AssetBundle.
      • CRC
      • Asset file hash. A single hash for all the assets included in this AssetBundle, only used for incremental build check.
      • Type tree hash. A single hash for all the types included in this AssetBundle, only used for incremental build check.
      • Class types. All the class types included in this AssetBundle. These are used to get the new single hash when doing the type tree incremental build check.
      • Asset names. All the assets explicitly included in this AssetBundle.
      • Dependent AssetBundle names. All the AssetBundles which this AssetBundle depends on.
      • This manifest file is only used for incremental build, not necessary for runtime.
    7. Single manifest file. We generate a single manifest file which includes:
      • All the AssetBundles.
      • All the AssetBundle dependencies.
    8. Single manifest AssetBundle. It only contains an AssetBundleManifest object which has following APIs:
      • GetAllAssetBundles() which returns all the AssetBundle names in this build.
      • GetDirectDependencies() which returns the direct dependent AssetBundle names.
      • GetAllDependencies() which returns all the dependent AssetBundle names
      • GetAssetBundleHash(string) which returns the hash for the specified AssetBundle.
      • GetAllAssetBundlesWithVariant() which returns all the AssetBundles with variant.
    9. AssetBundle loading APIs changed, now we have:
      • AssetBundle.GetAllAssetNames(). Return all the asset names in the AssetBundle.
      • AssetBundle.GetAllScenePaths(). Return all the scene asset paths if it's a streamed scene AssetBundle.
      • AssetBundle.LoadAsset(). Load asset from AssetBundle.
      • AssetBundle.LoadAllAssets()
      • AssetBundle.LoadAssetWithSubAssets()
      • Asynchronous version also provided
      • We won’t return component type any more, please load the game object first and then look up the component on the object.
    10. Typetree is written to the AssetBundle by default. The only exception is Metro as it has different serialization solution.
    The above is the basic usage of how to use the new AssetBundle build system. What can you benefit from it?
    1. No complex building script any more.
    2. Unity handles the dependencies.
      • This means you don’t need to handle the dependencies by using PushAssetDependencies/PopAssetDependencies functions, as Unity knows all the dependencies and handles this for you. This can reduce a lot of your efforts.
    3. Incremental build check which means you only need to rebuild the AssetBundle which actually change. This includes two parts:
      • Incremental build check for asset file changes. We generate a single hash for all the assets in the AssetBundle. Only when the assets in the AssetBundles actually change, we will do the rebuild.
      • Incremental build check for type tree changes. We also generate a single hash for the type trees in the AssetBundle. By default, we will rebuild the AssetBundle if type tree changes, but you can ignore the type tree changes by setting IgnoreTypeTreeChanges flag.
    4. Don't force rebuild all the AssetBundles on the dependency chain.
      • We change the way how we store dependent objects, this allow you not rebuild all the AssetBundles on the dependency chain.
      • Let's have an example, we have a cube prefab which has a material which has a texture. If we mark the cube prefab into CubeAssetBundle, and mark the material into MaterialAssetBundle, then we change the texture on the material. In the old build system, we need to rebuild both the CubeAssetBundle and MaterialAssetBundle, as we need to rebuild the dependent objects. But in the new build system, we only need to rebuild the MaterialAssetBundle without rebuilding CubeAssetBundle.
    Btw: The new and the old build systems will coexist for a while, PLEASE DON'T MIX THEM WHEN YOU'RE BUILDING ASSETBUNDLES.

    AssetBundle Variant

    Another thing I want to describe a little more is AssetBundle variant. From Unity 5.0 b21, we have better AssetBundle variant support in the new build system, which can be used to achieve the same result as virtual assets.

    For example, you can set AssetBundle as variants like “MyAssets.hd”, “MyAssets.sd”(Make sure the assets exactly match in these two AssetBundles). The objects in these two variant AssetBundles will have the exactly same internal IDs which is ensured by the Unity build pipeline. So these two variant AssetBundles can be switched out arbitrarily with AssetBundles of different variant extension at runtime.

    Then how to set the AssetBundle variant?
    1. From UI. From Unity 5.0 b21, beside the AssetBundle Name UI, we add one more UI to set the variant name of the AssetBundle
    2. AssetImporter.assetBundleVariant. Except UI, you can also set the AssetBundle variant from script.
    The full AssetBundle name will be the combination of the AssetBundle name and the variant name. For example, if you want to add “MyAssets.hd” as a variant AssetBundle, you should set the AssetBundle name to “MyAssets” and AssetBundle variant to “hd”. And the final AssetBundle is “MyAssets.hd”.

    But if you only set the AssetBundle name like “MyAssets.hd”, then it’s just a normal AssetBundle which is not variant AssetBundle. And apparently “MyAssets”+“hd” and “MyAssets.hd”+”” cannot coexist as they lead to the same full AssetBundle name.

    Btw: It’s not compatible with the Editor simulation.

    Demo

    Based on the new build system, we also made a demo to demonstrate the usage of current AssetBundle system. You can download the demo at the below link, let me know if you can’t access it. And please based on Unity 5.0 b21 to run this demo.

    [EDIT]

    This is the up-to-date AssetBundle Manager Demo:
    http://unity3d.com/learn/tutorials/...undles-and-assetbundle-manager?playlist=17117


    This link is obsolete:
    http://files.unity3d.com/vincent/assetbundle-demo/users_assetbundle-demo.zip

    [/EDIT]

    It demonstrates:
    1. How to build AssetBundles in the new build system.
    2. How to use the single manifest AssetBundle.
    3. Automatic AssetBundle dependency resolving, loading & unloading.
    4. Editor simulation. With it enabled, you can use AssetBundles in Editor play mode without actually building them.
    5. Optional setup where to download all AssetBundles.
    6. Build pipeline build integration. Script to build the AssetBundles and copy them to StreamingAssets folder, then they can be packed into the player data when you’re building the player. Please use the “AssetBundles/Build Player” to build the player data.
    7. New version of WWW.LoadFromCacheOrDownload and feed 128 bit hash to it when downloading. You can get the hash from the single manifest AssetBundle.
    8. AssetBundle variant to achieve the same result as virtual assets. (It’s not compatible with the Editor simulation.)
    Please refer to the README file in the demo project to get more details on this.

    Any feedback are appreciated.
     
    Last edited by a moderator: Oct 26, 2015
  2. Reanimate_L

    Reanimate_L

    Joined:
    Oct 10, 2009
    Posts:
    2,788
    Assets/ScriptsForAssetBundleSystem/AssetBundleManager.cs(168,69): error CS1061: Type `UnityEngine.AssetBundleManifest' does not contain a definition for `GetAllAssetBundlesWithVariant' and no extension method `GetAllAssetBundlesWithVariant' of type `UnityEngine.AssetBundleManifest' could be found (are you missing a using directive or an assembly reference?)
     
  3. Tim-Wiese

    Tim-Wiese

    Joined:
    Jul 7, 2012
    Posts:
    77
    Thanks for this info Vincent!

    I sent an email to Unity support a few days ago about this info specifically. For now I had to make do with watching your UNITE presentation and taking screenshots of relevant info.

    I have a couple of questions/feature requests about the AssetBundle system in its current state:

    - Versioning AssetBundles Question. So right now with WWW.LoadFromCacheOrDownload you can pass in the Hash 128 or version number, and if Hash 128 doesn't match (or the version number is higher) then the new AssetBundle will be put into the cache. From my testing, every time I build a new bundle it will be added to the cache and over time my 4gb cache (on iOS/Android) will eventually fill up and then start to delete old unused bundles out of the cache.
    The problem I face is I don't want my cache to fill up with old bundles, I would much rather be able to tell it to overwrite the old bundle with the new one. This way I'm not filling up the cache with asset bundles I won't use.

    - The other question I have is regarding loading from AssetBundles, Probably sort of more of a feature request. So currently to load an asset from an AssetBundle I have to use the AssetBundle Name and the Asset's Name that is contained within.
    like this:

    //Load Bundle
    WWW www = WWW.LoadFromCacheOrDownload(assetBundleServerLocation + assetBundleName, manifest.GetAssetBundleHash(assetBundleName))

    AssetBundle loadedAssetBundle = www.assetBundle;

    //Load Asset
    Object obj = loadedAssetBundle.LoadAsset(assetName);

    So this requires anything that loads from an AssetBundle to have to know the AssetBundle name and Asset name. This reliance on strings from my previous experience can cause headaches. What happens when I change the name of my AssetBundle? Now I have to find all the things loading from that AssetBundle using a string and change them to the new one. Or if I change the name of a Asset, then I have to update the string names in the same way. So instead I have thought of a way to pass in the GUID of a asset then the AssetBundle system will lookup in a dictionary for you what the AssetName is and what AssetBundle it is in, the values are then the AssetBundleName and AssetName. You could then use these values to do the LoadFromCacheOrDownload and LoadAsset. This also means that your download system won't break if bundles are renamed or assets are renamed.
    This system would require a manifest to hold the GUID to AssetBundleName to AssetName relation for the lookup.

    Then for the part of making the GUID readable and human writable in the Inspector I have created a attribute which can be used to drag and drop an object then use that objects GUID as a string. Here is my code for this Attribute https://www.dropbox.com/sh/9fhjojlgwtla5l1/AADSJSEvOiE4l9B286jULyV9a?dl=0

    This functionality of finding an AssetName and AssetBundleName from a GUID at runtime would be a big help and ensure that when AssetBundles are renamed or Assets are renamed that nothing breaks.

    Thanks!
    Tim
     
  4. Deleted User

    Deleted User

    Guest

    Please use b21.
     
  5. Reanimate_L

    Reanimate_L

    Joined:
    Oct 10, 2009
    Posts:
    2,788
    Ahh of course......i forgot that i still use B20.....
     
  6. DanSuperGP

    DanSuperGP

    Joined:
    Apr 7, 2013
    Posts:
    408
    Hi Vincent,

    Thanks for posting this and all your hard work on Asset Bundles.

    What about packing the sprite sheets we make with Sprite Packer into the Asset Bundles? There isn't any way to mark them to be packed.

    It seems like using Sprite Packer prevents you from gaining the benefit of using asset bundles... or using asset bundles prevent you from gaining the benefits of the sprite packer.
     
  7. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
    All you need to do in this case is mark the assets that are being shared into a specific asset bundle. Once you do that the system automatically records the dependencies for you.

    It does require you to mark them to be belong to a specific asset bundle but this is the only way we could make the system a full incremental build system.

    For starters we now provide a simple asset bundle loading system that handles all of this for you. Due to the new API's it greatly simplifies things and provides builtin asset bundle simulation API.

    Over time we might include this higher level API which we now provide through scripts into the product in a more builtin way, but for now at the very least all the code is already written for you with a simple high level API and you can even go in and tweak for specific needs.


    I strongly suggest you check out the demo project and get a feel for it.
     
  8. touchtt21

    touchtt21

    Joined:
    Jan 15, 2015
    Posts:
    1
    Thanks for posting this, it's very helpful for the project that I'm working on. I seem to be having some trouble with download link though the host is not resolving, is anyone else having these issues?

    Edit:
    No longer an issue, was a DNS lookup issue on my end.
     
    Last edited: Jan 28, 2015
  9. relsirc

    relsirc

    Joined:
    Jul 3, 2013
    Posts:
    20
    I have a quick question, I want to try out the sample project where the bundle is online.

    So in order to do that, do I just change the kAssetBundlesPath = "/AssetBundles/"; at BaseLoader.cs to the url that I'm hosting the bundles?
     
  10. Deleted User

    Deleted User

    Guest

    Actually, the requirement makes sense to me. Maybe an API like Caching.RemoveFromCache(string, Hash128) will help you. But I'm not sure if it's gonna happen in 5.0 cycle.

    We will think about this to see if there is a way to feed this design into our asset pipeline. Thanks for the valuable feedback.

    Thanks
    Vincent
     
  11. Deleted User

    Deleted User

    Guest

    Yes. Please try it and let me know how it works.
     
  12. Deleted User

    Deleted User

    Guest

    It's a little different for Sprite Packer, the result of packing is not an asset. It will be written to Project\Library\AtlasCache as temporary data, and be built to the player data. So currently there is no way to build it to AssetBundle.

    We need to more investigation to find a way which can unify the building of player data and AssetBundles. Thanks for raising this issue.
     
    DanSuperGP likes this.
  13. relsirc

    relsirc

    Joined:
    Jul 3, 2013
    Posts:
    20
    I've uploaded the testbundles to my dropbox account, but I have no luck in displaying them in the actual device. The scene just loads but nothing else. (I'm using an adhoc provisioning instead of a development provisioning)

    When I tried running it in the simulator I got a crash, a run time error I think.


    (Filename: /Users/builduser/buildslave/unity/build/artifacts/generated/common/runtime/UnityEngineDebug.gen.cpp Line: 56)

    (lldb)
     
  14. Tim-Wiese

    Tim-Wiese

    Joined:
    Jul 7, 2012
    Posts:
    77
    I think ideally the API, Caching.RemoveFromCache(string, Hash128) could also do Caching.RemoveFromCache(string) //without the Hash128. Because then I don't have to keep track of previous Hashes somewhere, I can just clear out any AssetBundles that have that name. With the Hash version I would have to store on the users device what the current hashes for each bundle they have is.
     
  15. bsterling250DI

    bsterling250DI

    Joined:
    Sep 25, 2014
    Posts:
    78
    Your problem is solved already for you with this new Asset Bundle system by the manifest file. If your atlas is in its own bundle, than every one of your ui prefab bundles will reference it as a dependency and only download it once.
     
  16. bryantdrewjones

    bryantdrewjones

    Joined:
    Aug 29, 2011
    Posts:
    147
    Hi Vincent,

    Just to clarify -- we can't currently use atlases generated by the Sprite Packer in Asset Bundles? I was really hoping we could make use of Asset Bundles to support multi-resolution / SD vs. HD sprite swapping (in fact, that's what I thought the variant system was designed for!). No such luck? :(
     
  17. bsterling250DI

    bsterling250DI

    Joined:
    Sep 25, 2014
    Posts:
    78
    sounds to me like its current focus is things marked as textures not sprites. If you were using texturepacker instead of the sprite packer from unity though you could easily create your own texture sheets and those assets could be marked in this asset bundle system if sprite packer support won't be available for some time, i dont know how long it would take vincent and the guys to implement it.
     
    SmartAsh and tealm like this.
  18. DanSuperGP

    DanSuperGP

    Joined:
    Apr 7, 2013
    Posts:
    408
    Which is fine for stuff that I make for myself independently.

    At my job not so much. The problem isn't the price of TexturePacker... it's purchasing software not from an approved vender.
     
  19. bsterling250DI

    bsterling250DI

    Joined:
    Sep 25, 2014
    Posts:
    78
    ya i understand that for sure, that's the risk you run though when using beta software where you work. might be some other options for you with external software or something, i'm sure someone somewhere has written a texture sheet program that you can leverage, you just might have to write your own json parser for frame data.
     
  20. DanSuperGP

    DanSuperGP

    Joined:
    Apr 7, 2013
    Posts:
    408
    No, it doesn't work in 4.6 either.
     
  21. Tim-Wiese

    Tim-Wiese

    Joined:
    Jul 7, 2012
    Posts:
    77
    Can you clarify the difference between these two methods a little more?
    • GetDirectDependencies() which returns the direct dependent AssetBundle names.
    • GetAllDependencies() which returns all the dependent AssetBundle names
    I assume AllDependencies will return every bundle which any other bundle relies on. And DirectDependencies will return the bundles which the only the passed in AssetBundle relies on? But I haven't been able to test this yet.
     
  22. ronjart

    ronjart

    Joined:
    May 16, 2013
    Posts:
    101
    I'm really glad to see this thread!

    I'm eager to implement asset bundles into my application but the feature I'm missing is for Enlighten data to be packaged with a mesh. I've read that you are planning on implementing this feature so that is good news. Could you give me some more info on the time-frame on this (is it planned for 5.0)?

    Thank you for making these great tools for us.
     
  23. Reanimate_L

    Reanimate_L

    Joined:
    Oct 10, 2009
    Posts:
    2,788
    @Vincent Zhang : how about lightmaps data ie the lightmapSnapshot? how to pack and unload it with assetsbundles?
     
  24. Gizmoi

    Gizmoi

    Joined:
    Jan 9, 2013
    Posts:
    327
    From reading the docs and looking at the root manifest that was created, it looks like:
    • GetDirectDependencies() returns the asset bundles that this asset bundle is dependant on
    • GetAllDependencies() returns the assets bundles that this asset bundle is dependant on and the asset bundles that it's dependencies are dependant on
    For example, I have textures, materials, models and prefabs bundle.
    The texture and model bundles have no dependencies.
    The materials bundle is directly dependant on the textures bundle.
    The prefabs bundle is directly dependant on the models bundle and the materials bundle, and indirectly dependant on the textures bundle, because of its dependency on the materials bundle.


    I am interested to know how Asset Bundle and the Sprite Packer work together, if at all. I'd like to bundle up some or all sprites in my game, but I don't want to lose packing functionality.


    I'd also like to know if you can specify a file extension for asset bundles built via the new system. Unity generates a meta for these for source control which can clash with folder metas.
    Although I'd ideally like folders in Unity not to generate meta files tbh.
     
    Last edited: Jan 30, 2015
  25. Tim-Wiese

    Tim-Wiese

    Joined:
    Jul 7, 2012
    Posts:
    77
    Thanks Gizmoi! That makes sense now.
     
  26. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
    generally speaking I would never put asset bundles in version control. They are outputs of the build pipeline and can now be rebuild incrementally. That doesn't belong in version control.

    You can add any extension you like. As a general convention in unity we usually use .unity3d
    but up to you...
     
  27. Gizmoi

    Gizmoi

    Joined:
    Jan 9, 2013
    Posts:
    327
    I intend to build my assets in a separate Unity project, and then import the asset bundle into my main project only.
    We have too much audio and many textures and sprites to keep in the main project now.

    How would I go about add an extension? I can only specific the asset bundle tag and then it is built automatically?
     
  28. jordiboni

    jordiboni

    Joined:
    Aug 14, 2013
    Posts:
    26
    I generated a new scene with a terrain mesh and I added some SpeedTree instances from "Sample Trees for Unity Subscription". I set correctly the asset bundle name in Inspector for the prefab.

    I use Unity 5.0b21 and it takes all my CPU power and Unity doesn't export the AssetBundle (Does Unity hang in an arbitrary endless loop?)

    If I remove SpeedTree instances, it works fine and generate the assetbundle.
     
  29. Gizmoi

    Gizmoi

    Joined:
    Jan 9, 2013
    Posts:
    327
    I noticed when building mine that, on occasion, it did lock up the editor for a minute or so. Then continued to build the asset bundles fine. Even when the bundles were up-to-date.

    I found it useful to put up an empty progress bar just before you call BuildPipline.BuildAssetBundles.
     
  30. Gizmoi

    Gizmoi

    Joined:
    Jan 9, 2013
    Posts:
    327
    Sorry for the double post, but:

    Does anyone know if it's possible to specify the name of an asset in an asset bundle in the new system? Similar to BuildPipeline.BuildAssetBundleExplicitAssetNames?

    I essentially want to cut off a fixed string from part of the path.
     
  31. Deleted User

    Deleted User

    Guest

    Just specify the AssetBundle tag like mytextures.unity3d, the .unity3d will be used as the extension. Of course you can add any extension you like.
     
    Gizmoi likes this.
  32. Deleted User

    Deleted User

    Guest

    Unfortunately there is no way to specify the name of the asset in the new system.
     
  33. Ferazel

    Ferazel

    Joined:
    Apr 18, 2010
    Posts:
    517
    Apologies if any of this is already available, but I've been perusing the new AssetBundle mechanics and have some questions/suggestions.

    First, just a recommendation about the cleaning cache issue. Why not just a Caching.ClearOlderVersions(url, hash) that would just delete out all older versions of that url without the need to remember the hash for all of the older versions. However, after thinking about this, would you ever want to keep an older version of the asset bundle after downloading a new version? Could we just make it happen by default when a new LoadFromCacheOrDownload needs to download the AssetBundle that it purges older versions of that AB from the file system after download?

    If AssetBundles are truly going to be a replacement for the Resources directory. Is there a good way to include the ABs locally with a build to the platform to be included in the App download or do we have to use a "file://" url request to the streaming assets folder? Is there an automated way to do this currently? While for some apps an additional download is an acceptable user experience, not being able to play the game after it downloads is sometimes not desired. So including at least a low quality set of asset bundles would be ideal with each app distribution. This is also useful for apps that don't want to setup an external server for downloading resources and paying for the bandwidth of pirates. Also ABs distributed this way could get the best of both worlds. Let's say that App bundled ABs would be included into the cache automatically. Then, if the device has an internet connection and validated their resources, they could receive minor AB updates until the next version of the app is released on the store. Hopefully, that makes sense why I'd like to have this feature.

    Correct me if I'm wrong, but currently there is only 1 asset to 1 AssetBundle right? So let's say we have a grass texture that has variants for resolution/compression/filtering settings you would have to have duplicate that texture asset for each variation? Would it be possible to have an AssetRef asset that points to another, but with different asset settings? Basically, make a symlink/alias asset that points to another raw asset? That way we only need to update one texture to create all of the variants rather than having to update all of the duplicated assets.

    The variant system is really exciting though, I hope you can add atlas and editor support soon. Some uses for this off the top of my head are:
    - Support for independent quality settings for textures, models, materials, prefabs and potentially manage them independently. High quality models with low quality textures for example.
    - Support for downloading only the assets that you want/need on your device. (No more wasting space on low/med if all you want are high resolution textures)
    - Support for AssetBundles that are keyed to a specific texture compression for certain devices. Although we would need a runtime supported device texture compression enum which I don't believe exists without writing a native plugin. This would be a huge win for kickstarting ASTC on devices that support it while having a separate AssetBundle for those that don't.

    Anyways, good work on getting this ready. I hope to see more AssetBundle improvements in 5.x.
     
    tangyikejunn likes this.
  34. Gizmoi

    Gizmoi

    Joined:
    Jan 9, 2013
    Posts:
    327
    Is it possible to load in the manifest produced by Asset Bundle creation?
    If not, what is their intended purpose? Are they simply a post-build sanity check?
     
  35. any_user

    any_user

    Joined:
    Oct 19, 2008
    Posts:
    374
    I think this is a very important point. I'm currently using this approach (building asset bundles to the streaming asset folder) but if it really should replace the Resources folder we need a simple way to include asset bundles in the build.

    This could be in the form of a list of all asset bundle names in the build settings window, with checkboxes if they are included in the build or not. If this checkbox is activated, the bundles will be automatically rebuilt when exporting the game and included in the resulting build.

    From code, the call to load from a bundle would be simple like this:

    Code (CSharp):
    1. Assets.GetBundle("resources").LoadAsset("myasset"); // instead of  Resources.Load("myasset")
    2.  
    In the editor, the returned asset bundle from GetBundle could then return a "virtual" proxy asset bundle that points to the editor assets directly instead of having to write different code for the editor with AssetDatabase.GetAssetPathsFromAssetBundleAndAssetName

    The workflow with a system like this would be like this: To load an asset by name we'd only have to mark this asset as part of an asset bundle, check that the asset bundle is included in the build (checkbox active) and write this one line of code mentioned above to load it.

    In addition, to keep track of asset bundle that are not included in the build, there could be some methods that allow us to register externally loaded bundle with this system. In the above example, GetBundle only returns something if the asset is included in the build or manually registered, like this:

    Code (CSharp):
    1.  
    2. if(!Assets.IsBundleRegistered("resources"))
    3. {
    4.    AssetBundle bundle = GetMyBundleFromSomewhere("resources"); // custom function to load bundle from www or file
    5.    Assets.RegisterBundle("resources",bundle);
    6. }
    7.  
    8. Assets.GetBundle("resources").LoadAsset("myasset");
    9.  
    10. // unregister the bundle if it is not needed anymore
    11. Assets.UnregisterBundle("resources");
    12.  
    I really think all this should be built-in functionality, most of people will need this when working with asset bundles. If you need more advanced control, you could still build your own system to keep track of the bundles.


    And about the not supported sprite atlases I'm a bit confused: Is it really, REALLY not supported? I'm using asset bundles for my iOS game which include a lot of packed sprites for animations. I always assumed would anyway crash without packing the sprites, so I never checked, but I've never had problems with it. Are you 100% sure they are not used - or did I just found a HUGE optimiziation possibility here? :)

    Also, looking at the editor logs, the occasional editor locks when building asset bundles seem to be caused by the sprite packer that rebuilds the atlases (without any feedback to the user), in my case at least.
     
    Ostwind likes this.
  36. Gizmoi

    Gizmoi

    Joined:
    Jan 9, 2013
    Posts:
    327
    I would also like to know how packing works in conjunction with the new Asset Bundle system.
     
  37. Anozireth

    Anozireth

    Joined:
    Feb 7, 2013
    Posts:
    71
    Happy to admit I couldn't have been more wrong here. My comments were based on my impression of the new system from attending the asset bundle presentation at the Unite conference, and clearly you have been hard at work since then.

    The new system does manage the dependencies exactly as I desired. I integrated the build side into my project and it takes the time for a full bundle build from around 10 minutes using our current system to 45-60 seconds with the new system, and an incremental build with no changes from 2-3 minutes to less than one second, both of which are very impressive. I've looked at the loading side, and it looks like the scripts provided do what I'm looking for there as well. I haven't had a chance to integrate them into the project yet, but it looks promising. So I apologize for commenting without looking more closely at the new system.
     
  38. Anozireth

    Anozireth

    Joined:
    Feb 7, 2013
    Posts:
    71
    I agree with the above commenters that it is essential to have a way to include certain bundles in the built player (streaming assets folder), and have them be loaded from there unless there is a newer one downloaded or available to download. I have looked and I'm not currently seeing a way to do this.

    We have also been building uncompressed bundles and then compressing them ourselves before upload. Then at runtime, we download it, decompress it and delete the compressed version before loading it into the asset bundle system. We do this because we don't want to pay the decompression cost more than once, but we don't want our users to have to download uncompressed bundles, both for user experience and our bandwidth costs. Will the new system do something similar to give the performance of uncompressed bundles but the download size of compressed bundles?

    I think with these two features, it would meet all of our needs with built-in functionality.
     
  39. DanSuperGP

    DanSuperGP

    Joined:
    Apr 7, 2013
    Posts:
    408
    Do you mean Sprite Packing?

    The answer, which is above in the thread, is that it doesn't.
     
  40. Gizmoi

    Gizmoi

    Joined:
    Jan 9, 2013
    Posts:
    327
    Ah yes, I see. Should've probably made sure I read the whole thread thoroughly.
    That's a shame, as most of our game is built from the new UI and hence, sprites.
     
  41. bsterling250DI

    bsterling250DI

    Joined:
    Sep 25, 2014
    Posts:
    78
    @Vincent Zhang: i notice that the BaseLoader.cs doesn't have BuildTarget.WebGL or RuntimePlatform.WebGL listed, was this deliberate due to a limitation of WebGL or was it just simply left out because WebGL is still in development?
     
  42. Deleted User

    Deleted User

    Guest

    We're looking into it now, to make sure it works with streamed scene AssetBundle.
     
  43. Deleted User

    Deleted User

    Guest

    It just simply left out, it should work with WebGL.
     
  44. Ferazel

    Ferazel

    Joined:
    Apr 18, 2010
    Posts:
    517
    Yes! This should be something that should be prioritized as well. You should be able to upload/download compressed AssetBundles but locally on the filesystem is should be uncompressed in the Caching system. I'm not sure if the LoadFromCacheOrDownload does this because the documentation is not explicit. Could we get confirmation that this happens automatically when using this method?

    According to the manual it states "If the AssetBundles in the StreamingAssets folder are compressed, you will need to use WWW.LoadFromCacheOrDownload to create an uncompressed copy of the AssetBundle in cache." http://docs.unity3d.com/Manual/abfaq.html

    However, if that is the case, is there a reason to call Unload() on ABs that are cached via the WWW method? Or is it only for AssetBundles created from files/memory?
     
  45. Gizmoi

    Gizmoi

    Joined:
    Jan 9, 2013
    Posts:
    327
    I'm sure I read somewhere regarding the potential removal of Resources in the future that Resources is just an Asset Bundle under the hood anyway.
    At the moment I place prefabs in my resources folder and load them from script.

    Under the new system, can I build an Asset Bundle of just prefabs and not the assets they depend on?
    I want to be able to have a reference to the prefabs in the bundle, but not the assets, as they will already be in the project.
     
  46. superpig

    superpig

    Drink more water! Unity Technologies

    Joined:
    Jan 16, 2011
    Posts:
    4,657
    The way to do this will be to put all the prefabs in one bundle (like 'MyPrefabs.bundle') and put all the assets they depend on in another bundle (like 'PrefabResources.bundle'). At runtime you'd load both bundles, then instantiate things from your MyPrefabs bundle, and they'll automatically use the copies of resources in the PrefabResources bundle.

    I'd ask, though: why do you want to do this? Are the assets you're looking at not being exclusively used by the prefabs? If they are, then why not just pack them into the MyPrefabs bundle with the prefabs themselves?
     
  47. Gizmoi

    Gizmoi

    Joined:
    Jan 9, 2013
    Posts:
    327
    The assets the prefabs depend on are mostly sprites. If I put them in a bundle then I'll lose the benefits of sprite packing. Also, yes, the assets are used elsewhere in the project, assigned in scenes.

    Previously, when loading things at run-time, I'd built something with a reference to the assets or collection of assets and put the reference in Resources to be loaded at runtime.
    For example I'd have an object with a reference to a sprite in Resources, meaning the sprite is still packed as it is not in resources, and I can load the reference and still access the sprite.
    I can't do this anymore if I wish to convert to Asset Bundles entirely. As when I build anything to a bundle it must have it's dependencies built into the same or another bundle.

    I wish to only have the assets I need load by filename built into bundles.
    By putting them into bundles it means don't have to worry about re-importing them when I switch platform, clone the repository or when Unity 'misplaces' parts of the Library.
    However at the moment I don't see a way to use Bundles effectively.

    Sorry for the ramble, I've come across a few roadblocks with the new system. Which is otherwise much improved.
     
  48. superpig

    superpig

    Drink more water! Unity Technologies

    Joined:
    Jan 16, 2011
    Posts:
    4,657
    Yes, the lack of sprite packing when building bundles is a known limitation of the implementation as it currently stands. It's something we want to fix.

    I believe you can pack the scenes themselves into Asset Bundles too, so the same dependency rules would apply. (This also means that when you want to do a new build of your game, the system should skip rebuilding the scenes that haven't changed, bringing your build times down).

    Actually I've got a feeling that doing this is duplicating your sprite sheets into both the Resources bundle and the main game data. Have you checked? (Should be possible to test building something with a few massive textures referenced both by the scene and by something in the Resources folder; if both Resources and mainData come out huge then that suggests they're being duplicated).

    (Thanks for the feedback, btw! There's more work still to be done on the Asset Bundles system for sure, we're not stopping with 5.0. The more you tell us about your use cases, the better).
     
    Gizmoi likes this.
  49. Gizmoi

    Gizmoi

    Joined:
    Jan 9, 2013
    Posts:
    327
    I know it's a limitation, I think it's the major thing stopping me from building most asset bundles at the moment. Most of our game is sprites unfortunately.

    Personally, it would be nice to have a warning stating that "these assets are dependencies and are not scheduled to be built into bundles" giving me an option to include them, with an overloaded BuildPipeline method to suppress/ignore this.
    It's also then clearer which assets are included in a bundle and it gives me the option to manage or partially manage my dependencies. I tend to mostly manage my own dependencies anyway, having all textures in one bundle, all materials in another etc.

    I don't particularly want to build scenes into bundles at this point, as I want to put the assets I'm building into another Unity project for the art team to use, meaning I only need the built bundles in the main project. At least for things I want to load at run-time; which generally is anything there is a vast amount of.

    I'll test the duplicate assets in Resources and report back.
    Thanks for the replies, it's encouraging to know you guys are working on our concerns.
     
  50. maxthecat

    maxthecat

    Joined:
    May 26, 2014
    Posts:
    29
    Is the plan to remove the old 4.6 build system?