Assign assets to an AssetBundle
Assign assets to AssetBundles in the Editor or through scripts.
Read time 2 minutesLast updated a month ago
To build assets into an AssetBundle, you must first assign assets to an AssetBundle, either in the Unity Editor or through a script. You can then create and use a script to build the AssetBundles. For information on the best approaches for organizing assets into AssetBundles, refer to Organizing assets into AssetBundles.
Assign assets to AssetBundles in the Editor
To assign a given asset to an AssetBundle in the Unity Editor, perform the following steps:
- Select the asset in the Project window and view it in the Inspector.
- Use the AssetBundle left-hand dropdown menu at the bottom of the Inspector window to assign or create an AssetBundle:
- To create a new AssetBundle, select the left-hand dropdown and select New, or choose an existing AssetBundle from the list. Tip: To organize AssetBundles with subfolders, use the character. For example, use the AssetBundle name
/to create an AssetBundle namedenvironment/forestunder anforestsubfolder.environment
- To create a new AssetBundle, select the left-hand dropdown and select New, or choose an existing AssetBundle from the list. Tip: To organize AssetBundles with subfolders, use the
- Optionally use the right-hand menu to assign or create an AssetBundle variant:
- To create a new variant, select the right-hand dropdown and select New, or choose an existing variant from the list.
Assigning multiple assets to an AssetBundle
You can assign an AssetBundle to a folder in your project. By default, all assets in that folder are assigned to the same AssetBundle as the folder. However, the AssetBundle assignments for individual assets takes precedence. To assign an AssetBundle to a folder:
- Select the folder in its containing parent folder the Project window.
- Use the AssetBundle dropdown to assign a new or existing AssetBundle to the folder.
You can also select multiple assets and assign them to an AssetBundle. However, assigning assets to an AssetBundle in this way overrides any existing AssetBundle assignments for those assets.
Assign assets to AssetBundles with a script
To assign assets to AssetBundles in your code, use the method with an array of structures. This approach overrides any AssetBundle assignments made in the Inspector.
BuildPipeline.BuildAssetBundlesAssetBundleBuildIf you want your script to respect AssetBundle assignments made in the Inspector, use and to retrieve the necessary information and populate the array.
AssetDatabase.GetAllAssetBundleNamesAssetDatabase.GetAssetPathsFromAssetBundleAssetBundleBuild