unity-game-enginebuildassetsassetbundle

Unity - Is it necessary to exclude assets being used in AssetBundles from game build?


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.


Solution

  • 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.