{"record":{"id":"17649806846e1d27","repo":"Unity-Technologies/UnityCsReference","slug":"value-for-parameter-atlases-is-null","errorCode":null,"errorMessage":"Value for parameter atlases is null","messagePattern":"Value for parameter atlases is null","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"Editor/Mono/2D/SpriteAtlas/EditorSpriteAtlas.bindings.cs","lineNumber":28,"sourceCode":"using UnityEditor.AssetImporters;\nusing UnityEngine.UIElements;\n\nnamespace UnityEditor.U2D\n{\n    [NativeHeader(\"Runtime/2D/SpriteAtlas/SpriteAtlas.h\")]\n    [NativeHeader(\"Editor/Src/2D/SpriteAtlas/SpriteAtlasPackingUtilities.h\")]\n    public class SpriteAtlasUtility\n    {\n        [FreeFunction(\"CollectAllSpriteAtlasesAndPack\")]\n        extern public static void PackAllAtlases(BuildTarget target, bool canCancel = true);\n\n        [FreeFunction(\"PackSpriteAtlases\")]\n        extern internal static void PackAtlasesInternal(SpriteAtlas[] atlases, BuildTarget target, bool canCancel = true, bool invokedFromImporter = false, bool unloadSprites = false);\n\n        public static void PackAtlases(SpriteAtlas[] atlases, BuildTarget target, bool canCancel = true)\n        {\n            if (atlases == null)\n                throw new ArgumentNullException(\"atlases\", \"Value for parameter atlases is null\");\n            foreach (var atlas in atlases)\n                if (atlas == null)\n                    throw new ArgumentNullException(\"atlases\", \"One of the elements in atlases is null. Please check your Inputs.\");\n            PackAtlasesInternal(atlases, target, canCancel, false, true);\n        }\n\n        [FreeFunction(\"GetSpriteTexture\")]\n        extern internal static Texture2D GetSpriteTexture([NotNull] Sprite sprite, bool fromAtlas);\n\n        [FreeFunction(\"SpriteAtlasExtensions::CleanupAtlasPacking\")]\n        extern public static void CleanupAtlasPacking();\n\n        [FreeFunction(\"SpriteAtlasExtensions::OnSpriteAtlasSettingsChanged\")]\n        extern internal static void OnSpriteAtlasSettingsChanged();\n    }\n\n\n    [StructLayout(LayoutKind.Sequential)]","sourceCodeStart":10,"sourceCodeEnd":46,"githubUrl":"https://github.com/Unity-Technologies/UnityCsReference/blob/225b0fbdb57cc17d094e8056b71f8314aba56f73/Editor/Mono/2D/SpriteAtlas/EditorSpriteAtlas.bindings.cs#L10-L46","documentation":"Thrown by SpriteAtlasUtility.PackAtlases when the atlases array argument is null. PackAtlases packs a caller-supplied set of SpriteAtlas assets into textures via the native PackAtlasesInternal; before delegating it asserts the array exists. ArgumentNullException is used because the whole parameter (not just an element) is missing, so there is nothing to iterate.","triggerScenarios":"Calling SpriteAtlasUtility.PackAtlases(null, target). Passing a field/property that was never assigned (e.g. a SerializedProperty.objectReferenceValue-derived array that came back null). Forwarding the result of FindObjectsByType or AssetDatabase.FindAssets that returned nothing and got coerced to null.","commonSituations":"Editor build scripts and CI batch packing pipelines that gather atlases dynamically. PostImport or BuildPlayer callbacks that pack atlases where asset loading failed silently. Menu-item automation where the user forgot to select atlases in the Project window.","solutions":["Initialize atlases via AssetDatabase.FindAssets(\"t:SpriteAtlas\") and LoadAssetAtPath before calling PackAtlases.","Guard with 'if (atlases == null || atlases.Length == 0) return;' for optional-pack workflows.","Log a clear message and skip when the selection/gather step yields null instead of forwarding it.","Verify the array is populated in the same scope that creates it, not in a deferred callback."],"exampleFix":"// before\nSpriteAtlasUtility.PackAtlases(null, BuildTarget.StandaloneWindows64);\n\n// after\nvar guids = AssetDatabase.FindAssets(\"t:SpriteAtlas\");\nvar atlases = guids.Select(g => AssetDatabase.LoadAssetAtPath<SpriteAtlas>(AssetDatabase.GUIDToAssetPath(g))).ToArray();\nif (atlases == null || atlases.Length == 0) { Debug.LogWarning(\"No sprite atlases found; skipping pack.\"); return; }\nSpriteAtlasUtility.PackAtlases(atlases, BuildTarget.StandaloneWindows64);","handlingStrategy":"validation","validationCode":"if (atlases == null) { Debug.LogWarning(\"atlases is null; nothing to pack.\"); return; }","typeGuard":"static bool HasAtlases(SpriteAtlas[] a) => a != null && a.Length > 0;","tryCatchPattern":null,"preventionTips":["Always derive atlases from AssetDatabase.FindAssets + LoadAssetAtPath so the array is populated.","Add a null/empty guard at the entry of every batch-pack routine.","Never forward unchecked external inputs (selection, config) to PackAtlases."],"tags":["sprite-atlas","argument-null","editor","asset-pipeline","csharp"],"backgroundTag":null,"analyzedSha":"225b0fbdb57cc17d094e8056b71f8314aba56f73","analyzedAt":"2026-08-13T19:07:19.849Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}