6

Having a difficult time finding much information on how AssetBundles actually work. Can't find any explanation on how to manage asset bundles with a game build.

Basically I have a folder called AssetBundles in my Project window. All assets that I put in this folder are built as AssetBundles in a folder within my build directory (like GameName/Data/AssetBundles) which are then loaded when needed.

But when I build the game itself, does it know not to include these assets that are being used in AssetBundles in the game build? Or do I need to exclude them in some way?

Edit: I've made some progress.

To my understanding, only assets of which reside in scenes that are in the build settings will be built with the game build. Scripts are always built in the game build (I'm not sure if there's a way of getting around this but it's not an issue to me).

So I have a single scene which is in the game build which acts as the startup object of the game. This scene has an Asset Manager script on it with DontDestroyOnLoad specified in Awake.

My asset manager script basically just handles loading/unloading of bundles, assets and instances.

I'm currently not too sure about how building asset bundles for scenes work. I have it working using LoadAllAssets and then doing LoadLevel, but what if multiple scenes share some assets? Do scene builds end up bloated having copies of assets that can be shared? I read that dependencies are automatically handled in Unity 5, but I'm not sure if that relates to this.

Sakuya
  • 660
  • 5
  • 23

2 Answers2

2

I found the below post which has a sample project with different ways of using AssetBundles in Unity 5.

http://forum.unity3d.com/threads/new-assetbundle-build-system-in-unity-5-0.293975/

It includes an example of building/loading scenes and it seems to work correctly (it automatically determines dependencies.. so all you have to do is ensure you build shared assets in a shared asset bundle (or their own bundle) for efficiency).

The only thing I was doing differently on the build is defining AssetBundleBuild (basically I organized my project folder so that assets are stored in subfolders which correlate to their assetbundle names, and then on build it checks these folders and adds them).

For some reason my method of doing that seems to break dependencies whereas using the asset bundle feature in the editor ui seems to work (manually naming the bundle for every asset.. which is a bit tedious if you have hundreds of assets in several different bundles) and then using BuildAssetBundles without the builds argument.

I still don't really have an answer to my original question Is it necessary to exclude assets being used in AssetBundles from game build?

But to be safe, I only have 1 scene actually being built in the game build, and that scene just has an asset manager script on which handles asset bundles and it doesn't destroy on load. No need to have other scenes being built if you have them all as asset bundles.

Sakuya
  • 660
  • 5
  • 23
0

When you build the game it should only use the assets that are in the build as in anything that you use or is a dependency of anything used in the build.

Justin Markwell
  • 341
  • 6
  • 13
  • But doesn't that include objects in scenes and scenes themselves? Even if I build those as asset bundles? – Sakuya Sep 19 '15 at 04:19
  • What I assume you mean is that anything used in scenes will be built in the game build if those scenes are in the build settings, so assets that are being built as asset bundles cannot be present in those scenes during game build? So if I want to make changes to things in the inspector in a scene, I would have to: Remove assets from scene and place them in bundle folders > build bundles that need updating > build game > re-add assets to scene. I guess I'm going to need to write a script for it? – Sakuya Sep 19 '15 at 04:38
  • No It should not duplicate anything it will determine what is being used. – Justin Markwell Sep 19 '15 at 14:51
  • I did a test by having a scene which is loaded from assetbundle, and the scene contains a cube prefab that is from another assetbundle. I build both assetbundles. – Sakuya Sep 19 '15 at 22:08
  • Sorry I accidentally posted that before finishing and cant edit: I did a test by having a scene which is loaded from assetbundle, and the scene contains a cube prefab that is from another assetbundle. In build #1 of the scene assetbundle with the cube, the size is 70kb. In build #2 of this scene I removed the cube before building and its size dropped to around 40kb. The cube assetbundle itself is 32kb. This leads me to believe that the scene assetbundle is storing the cube in its own bundle instead of referencing it. Could you post a working example so I know what I might be doing wrong? – Sakuya Sep 19 '15 at 22:16
  • Also, when I check the manifest files, the cube isn't showing as a dependency. – Sakuya Sep 19 '15 at 22:21