{"record":{"id":"17803c123945045f","repo":"Unity-Technologies/UnityCsReference","slug":"assetbundlebuild-cannot-be-null","errorCode":null,"errorMessage":"AssetBundleBuild cannot be null.","messagePattern":"AssetBundleBuild cannot be null\\.","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"Editor/Mono/BuildPipeline/BuildPipeline.bindings.cs","lineNumber":569,"sourceCode":"        ///                    of the bundles programmatically, using a \"build map\" rather than with the details set in the editor.\n        ///                    The map is simply an array of <see cref=\"AssetBundleBuild\" /> objects, each of which contains\n        ///                    a bundle name and a list of the names of asset files to be added to the named bundle.\n        ///\n        ///                    For new code, the signature of BuildAssetBundles accepting a BuildAssetBundlesParameters structure is recommended\n        ///                    instead of this one.  When using that signature the build map is assigned to <see cref=\"BuildAssetBundlesParameters.bundleDefinitions\" />.</remarks>\n        ///<param name=\"outputPath\">Output path for the AssetBundles.</param>\n        ///<param name=\"builds\">AssetBundle building map.</param>\n        ///<param name=\"assetBundleOptions\">AssetBundle building options.</param>\n        ///<param name=\"targetPlatform\">Target build platform.</param>\n        ///<returns>The manifest listing all AssetBundles included in this build.</returns>\n        ///<example>\n        ///  <code source=\"../../../Modules/ContentBuild/Tests/local.test.build-examples/Editor/BuildPipeline/BuildPipeline_BuildAssetBundles2.cs\"/>\n        ///</example>\n        public static AssetBundleManifest BuildAssetBundles(string outputPath, AssetBundleBuild[] builds, BuildAssetBundleOptions assetBundleOptions, BuildTarget targetPlatform)\n        {\n            if (builds == null)\n                // This signature is specifically meant for specifying the bundle definition array, so it is not optional\n                throw new ArgumentException(\"AssetBundleBuild cannot be null.\");\n\n            BuildAssetBundlesParameters input = new BuildAssetBundlesParameters\n            {\n                outputPath = outputPath,\n                bundleDefinitions = builds,\n                options = assetBundleOptions,\n                targetPlatform = targetPlatform,\n                subtarget = EditorUserBuildSettings.GetActiveSubtargetFor(targetPlatform),\n            };\n\n            return BuildAssetBundles(input);\n        }\n\n        ///<summary>Builds the AssetBundles in your project.</summary>\n        ///<remarks>\n        ///  <para>This signature of BuildAssetBundles is recommended and exposes the most functionality. The other signatures, documented below,\n        ///are retained for backward compatibility and convenience.\n        ///","sourceCodeStart":551,"sourceCodeEnd":587,"githubUrl":"https://github.com/Unity-Technologies/UnityCsReference/blob/225b0fbdb57cc17d094e8056b71f8314aba56f73/Editor/Mono/BuildPipeline/BuildPipeline.bindings.cs#L551-L587","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nAssetBundleBuild[] builds = LoadBundleMap(configPath); // returns null\nBuildPipeline.BuildAssetBundles(outputPath, builds, BuildAssetBundleOptions.None, BuildTarget.StandaloneWindows64);\n\n// after\nAssetBundleBuild[] builds = LoadBundleMap(configPath) ?? Array.Empty<AssetBundleBuild>();\nBuildPipeline.BuildAssetBundles(outputPath, builds, BuildAssetBundleOptions.None, BuildTarget.StandaloneWindows64);","handlingStrategy":"type-guard","validationCode":"if (builds == null)\n{\n    Debug.LogError(\"AssetBundleBuild array is null. If definitions are optional, use the overload without the builds parameter.\");\n    builds = Array.Empty<AssetBundleBuild>();\n}","typeGuard":"static AssetBundleBuild[] EnsureBundleDefinitions(AssetBundleBuild[] builds)\n{\n    return builds ?? Array.Empty<AssetBundleBuild>();\n}","tryCatchPattern":null,"preventionTips":["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."],"tags":["unity","build-pipeline","asset-bundles","null-argument","argument-validation"],"backgroundTag":null,"analyzedSha":"225b0fbdb57cc17d094e8056b71f8314aba56f73","analyzedAt":"2026-08-13T19:07:19.849Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}