How do assetbundles actually work?

I’m using uncompressed local assetbundles, and I’d like some confirmation of their actual working.

When I call Assetbundle.CreateFromFile() at that point, are all contained assets loaded into memory, or just made accessible for instantiation?

I ask, as I’d like to instantiate certain assets, at any time during gameplay, and am wondering if I should (a) Get all contained assets into memory at once, and instantiate as needed, or (b) Get the required assets, and unload the ones that are not needed.

Obviously (a) would take up more memory at runtime, and (b) would take longer.

Are there any hard and fast do’s and dont’s for assetbundle use? I’m looking to improve my understanding of them (which wouldn’t be hard).

Many thanks :slight_smile:

I’ve recently started using AssetBundles and here is some of the stuff I learned/noticed while implementing them in our game.

First off, let’s start with what is an AssetBundle? And what are they used for?

An AssetBundle is pre-packaged group of assets (audio, textures, meshes, prefabs, materials, etc) built through the Unity Editor. It can be used to stream large sets of assets into your game without much of a hit to performance (if any at all). AssetBundles can be streamed from a directory local to the PC or through the web. It can drastically reduce your build times (since AssetBundles only need to be build when the assets they contain change). If the build is a web-player you can use AssetBundles to help you reduce the initial size of the build and get the player started faster. I know I missed quite a few things but this should at least put AssetBundles into perspective.

Next, how do you build AssetBundles?

The API for this is called BuildPipeline.BuildAssetBundle. You can even find some scripts like the one here named ExportAssetBundles (which is the one i use) if you google a bit. I like ExportAssetBundles because you simply select the assets that you want to turn into an AssetBundle and hit a menu option.

How do I use AssetBundles?

I’ll get back to you on this, lol. It’s taking me so long to write this and I’m still at work. Ssshhh, don’t tell anybody :stuck_out_tongue:

How do I maintain my AssetBundles?

For our company, AssetBundle maintenance is not that big a deal since our AssetBundles only change once or twice after we build them the first time. If you will be using AssetBundles heavily it might be worth investing time into building an automated AssetBundles framework that is able to track the assets each asset bundle contains and knows to re-build them when necessary, like when you make a build of your game. There was a talk at a Unite conference about AssetBundles where a company talked about this very same thing. You might be able to find it, if not I’ll see if I still have it in my browsing history. The reason I bring this up is because it can become quite a nightmare to maintain AssetBundles with large teams if there are many people making constant changes to the assets they contain. Some reasons for this include knowing which assets are part of which bundles, determining who is responsible for building which bundles and when.

How do I make iterations with AssetBundles quicker?

One of the main benefits of using Unity is the speed of iteration using the Unity Editor. Make a quick change, then hit play. Rinse and repeat. AssetBundles can cripple this iteration workflow if you have to rebuild an AssetBundle every time you make a change just to iterate. This bit me in the butt, or is it on the butt? Whatever, point is that it’s probably worth your time to have your game load assets directly instead of the AssetBundles when running in the editor so that your iteration is unhindered. Once a final build (or test build for that matter) is made the necessary AssetBundles are rebuilt and the game loads from the AssetBundles instead.