Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 638
Sakuya Avatar asked Sep 18 '15 22:09

Sakuya


People also ask

Does unity include unused assets in build?

It should only include assets that are used (referenced). Additionally it will include anything in a Resources folder (excluding items in an Editor folder). But it is best to clean up your project folder, as when you switch build targets for other platforms, it will need to reimport all the assets.

How do you exclude a script from Unity build?

To do that, create a folder with the scripts you want to exclude and create an assembly definition asset inside. On the inspector in the included platforms section, only select Editor. This way, builds won't include the scripts. To exclude specific scripts, you can use the macro UNITY_EDITOR at the start of your code.

What is the use of asset bundle in unity?

AssetBundles can be useful for downloadable content (DLC), reducing initial install size, loading assets optimized for the end-user's platform, and reduce runtime memory pressure. Note: An AssetBundle can contain the serialized data of an instance of a code object, such as a ScriptableObject.

What does unity include in a build?

In software engineering, a unity build (also known as unified build or jumbo build) is a method used in C and C++ software development to speed up the compilation of projects by combining multiple translation units into a single one, usually achieved by using include directives to bundle multiple source files into one ...


1 Answers

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.

like image 52
Sakuya Avatar answered Oct 03 '22 16:10

Sakuya