Unity-Technologies/UnityCsReference · error · ArgumentException
AssetBundleBuild cannot be null.
Error message
AssetBundleBuild cannot be null.
What it means
Thrown by the BuildAssetBundles overload that explicitly accepts an AssetBundleBuild[] array when that array is null. Unlike other overloads where the bundle definitions are optional (read from AssetBundleBuildMap), this overload's entire purpose is to receive the definitions, so null is always invalid.
Source
Thrown at Editor/Mono/BuildPipeline/BuildPipeline.bindings.cs:569
/// of the bundles programmatically, using a "build map" rather than with the details set in the editor.
/// The map is simply an array of <see cref="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.
///
/// For new code, the signature of BuildAssetBundles accepting a BuildAssetBundlesParameters structure is recommended
/// instead of this one. When using that signature the build map is assigned to <see cref="BuildAssetBundlesParameters.bundleDefinitions" />.</remarks>
///<param name="outputPath">Output path for the AssetBundles.</param>
///<param name="builds">AssetBundle building map.</param>
///<param name="assetBundleOptions">AssetBundle building options.</param>
///<param name="targetPlatform">Target build platform.</param>
///<returns>The manifest listing all AssetBundles included in this build.</returns>
///<example>
/// <code source="../../../Modules/ContentBuild/Tests/local.test.build-examples/Editor/BuildPipeline/BuildPipeline_BuildAssetBundles2.cs"/>
///</example>
public static AssetBundleManifest BuildAssetBundles(string outputPath, AssetBundleBuild[] builds, BuildAssetBundleOptions assetBundleOptions, BuildTarget targetPlatform)
{
if (builds == null)
// This signature is specifically meant for specifying the bundle definition array, so it is not optional
throw new ArgumentException("AssetBundleBuild cannot be null.");
BuildAssetBundlesParameters input = new BuildAssetBundlesParameters
{
outputPath = outputPath,
bundleDefinitions = builds,
options = assetBundleOptions,
targetPlatform = targetPlatform,
subtarget = EditorUserBuildSettings.GetActiveSubtargetFor(targetPlatform),
};
return BuildAssetBundles(input);
}
///<summary>Builds the AssetBundles in your project.</summary>
///<remarks>
/// <para>This signature of BuildAssetBundles is recommended and exposes the most functionality. The other signatures, documented below,
///are retained for backward compatibility and convenience.
///View on GitHub (pinned to 225b0fbdb5)
Solutions
- Pass a non-null AssetBundleBuild[] array, even if empty, to the overload that requires it.
- If bundle definitions are optional, use the overload BuildPipeline.BuildAssetBundles(outputPath, options, target) that reads from the AssetBundle Build window / AssetBundleBuildMap instead.
- Add a null check before the call and log a meaningful error pointing to the configuration source.
Example fix
// before AssetBundleBuild[] builds = LoadBundleMap(configPath); // returns null BuildPipeline.BuildAssetBundles(outputPath, builds, BuildAssetBundleOptions.None, BuildTarget.StandaloneWindows64); // after AssetBundleBuild[] builds = LoadBundleMap(configPath) ?? Array.Empty<AssetBundleBuild>(); BuildPipeline.BuildAssetBundles(outputPath, builds, BuildAssetBundleOptions.None, BuildTarget.StandaloneWindows64);
Defensive patterns
Strategy: type-guard
Validate before calling
if (builds == null)
{
Debug.LogError("AssetBundleBuild array is null. If definitions are optional, use the overload without the builds parameter.");
builds = Array.Empty<AssetBundleBuild>();
} Type guard
static AssetBundleBuild[] EnsureBundleDefinitions(AssetBundleBuild[] builds)
{
return builds ?? Array.Empty<AssetBundleBuild>();
} Prevention
- If bundle definitions are optional, use BuildPipeline.BuildAssetBundles(outputPath, options, target) instead of the overload with builds.
- Initialize the builds array from a validated source and use null-coalescing to guarantee non-null.
- Add a null check with a meaningful log message before the call.
When it happens
Trigger: Calling BuildPipeline.BuildAssetBundles(outputPath, builds, options, target) where the builds argument is null — e.g., passing a variable that was never initialized or a collection that evaluated to null.
Common situations: A build script fetches bundle definitions from a configuration source that returned null, deserialization of a bundle map that produced null, or code refactoring that moved the array initialization into a conditional branch that wasn't taken.
Related errors
- Cannot build asset bundles while a build is in progress.
- The output path "{buildParameters.outputPath}" doesn't exist
- path
- paths
- The name is empty
AI-assisted analysis of Unity-Technologies/UnityCsReference@225b0fbdb5 (2026-08-13).
Data as JSON: /api/errors/17803c123945045f.
Report an issue: GitHub.