LanguageEnglish
  • C#
  • JS

Script language

Select your preferred scripting language. All code snippets will be displayed in this language.

BuildPipeline.BuildAssetBundles

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Sumbission failed

For some reason your suggested change could not be submitted. Please try again in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

public static function BuildAssetBundles(outputPath: string, assetBundleOptions: BuildAssetBundleOptions = BuildAssetBundleOptions.None, targetPlatform: BuildTarget = BuildTarget.WebPlayer): AssetBundleManifest;
public static AssetBundleManifest BuildAssetBundles(string outputPath, BuildAssetBundleOptions assetBundleOptions = BuildAssetBundleOptions.None, BuildTarget targetPlatform = BuildTarget.WebPlayer);

Parameters

outputPath Output path for the AssetBundles.
assetBundleOptions AssetBundle building options.
targetPlatform Target build platform.

Description

Build all AssetBundles specified in the editor.

From Unity 5.0, the editor lets you mark assets for inclusion in named AssetBundles (see the manual page about enhanced asset bundle workflow for further details). This function actually builds the bundles you have specified in the editor and will return true if the build was successful and false otherwise. Additionally, error messages are shown to explain most common build failures such as incorrect target folder paths.

The outputPath is a path to a folder somewhere within the project folder where the built bundles will be saved (eg, "Assets/MyBundleFolder"). The folder will not be created automatically and the function will simply fail if it doesn't already exist.

The optional assetBundleOptions modify the way the bundle is built while the targetPlatform selects which deployment target (standalone, mobile, etc) the bundle will be used with. Note that bundles built for standalone platforms are not compatible with those built for mobiles and so you may need to produce different versions of a given bundle. See the Asset Bundle FAQ in the manual for more information about bundle compatibility among platforms.

@MenuItem("Test/Build Asset Bundles")
static function BuildABs() {
	// Put the bundles in a folder called "ABs" within the
	// Assets folder.
	BuildPipeline.BuildAssetBundles("Assets/ABs");
}

See Also: AssetBundle, BuildPipeline.BuildAssetBundle.

public static function BuildAssetBundles(outputPath: string, builds: AssetBundleBuild[], assetBundleOptions: BuildAssetBundleOptions = BuildAssetBundleOptions.None, targetPlatform: BuildTarget = BuildTarget.WebPlayer): AssetBundleManifest;
public static AssetBundleManifest BuildAssetBundles(string outputPath, AssetBundleBuild[] builds, BuildAssetBundleOptions assetBundleOptions = BuildAssetBundleOptions.None, BuildTarget targetPlatform = BuildTarget.WebPlayer);

Parameters

outputPath Output path for the AssetBundles.
assetBundleOptions AssetBundle building options.
targetPlatform Target build platform.
builds AssetBundle building map.

Description

Build AssetBundles from a building map.

This variant of the function lets you specify the names and contents of the bundles using a "building map" rather than with the details set in the editor. The map is simply an array of AssetBundleBuild objects, each of which contains a bundle name and a list of the names of asset files to be added to the named bundle.

@MenuItem("Test/Build Asset Bundles")
static function BuildABs() {
	// Create the array of bundle build details.
	var buildMap: AssetBundleBuild[] = new AssetBundleBuild[2];
	
	buildMap[0].assetBundleName = "enemybundle";
	var enemyAssets: String[] = new String[2];
	enemyAssets[0] = "char_enemy_alienShip";
	enemyAssets[1] = "char_enemy_alienShip-damaged";
	buildMap[0].assetNames = enemyAssets;
	
	buildMap[1].assetBundleName = "herobundle";
	var heroAssets: String[] = new String[1];
	heroAssets[0] = "char_hero_beanMan";
	buildMap[1].assetNames = heroAssets;
	
	BuildPipeline.BuildAssetBundles("Assets/ABs", buildMap);
}