{"record":{"id":"ccb9b3f1505793c7","repo":"Unity-Technologies/UnityCsReference","slug":"one-of-the-elements-in-atlases-is-null-please-che","errorCode":null,"errorMessage":"One of the elements in atlases is null. Please check your Inputs.","messagePattern":"One of the elements in atlases is null\\. Please check your Inputs\\.","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"Editor/Mono/2D/SpriteAtlas/EditorSpriteAtlas.bindings.cs","lineNumber":31,"sourceCode":"namespace 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)]\n    public struct SpriteAtlasTextureSettings\n    {\n        [NativeName(\"anisoLevel\")]","sourceCodeStart":13,"sourceCodeEnd":49,"githubUrl":"https://github.com/Unity-Technologies/UnityCsReference/blob/225b0fbdb57cc17d094e8056b71f8314aba56f73/Editor/Mono/2D/SpriteAtlas/EditorSpriteAtlas.bindings.cs#L13-L49","documentation":"Thrown by SpriteAtlasUtility.PackAtlases during its per-element loop when at least one slot in the atlases array is null. Unlike the whole-array check, the array itself is valid but contains a missing reference, which the native packer cannot dereference. The message explicitly tells the developer to inspect the Inputs, i.e. the objects feeding the array.","triggerScenarios":"An array built with a placeholder null, or LoadAssetAtPath returning null for a bad path but still added to the list. Mixing valid SpriteAtlas objects with destroyed/unloaded ones (e.g. after Resources.UnloadUnusedAssets). A selection array containing a non-SpriteAtlas that got cast and failed silently.","commonSituations":"Custom editor windows that let users add atlas slots but leave some empty. Batch scripts that filter by name but a moved/renamed asset leaves a null entry. Prefab/asset-bundle build automation iterating a list that contains stale references.","solutions":["Filter nulls out before packing: atlases = atlases.Where(a => a != null).ToArray().","Validate each loaded asset immediately after LoadAssetAtPath and skip/log failures.","Use EditorUtility.CollectDependencies or a typed selector so only real SpriteAtlas objects enter the array.","If the empty slot is a user error, surface it in the editor UI before invoking PackAtlases."],"exampleFix":"// before\nvar atlases = selectedPaths.Select(p => AssetDatabase.LoadAssetAtPath<SpriteAtlas>(p)).ToArray();\nSpriteAtlasUtility.PackAtlases(atlases, target);\n\n// after\nvar atlases = selectedPaths\n    .Select(p => AssetDatabase.LoadAssetAtPath<SpriteAtlas>(p))\n    .Where(a => a != null)\n    .ToArray();\nif (atlases.Any(a => a == null)) { Debug.LogError(\"Some atlases could not be loaded.\"); return; }\nSpriteAtlasUtility.PackAtlases(atlases, target);","handlingStrategy":"validation","validationCode":"if (atlases == null || atlases.Any(a => a == null)) { Debug.LogError(\"atlases contains a null element.\"); return; }","typeGuard":"static bool AllAtlasesValid(SpriteAtlas[] a) => a != null && a.All(x => x != null);","tryCatchPattern":null,"preventionTips":["Filter nulls with .Where(a => a != null) after building the array.","Log each LoadAssetAtPath failure immediately so nulls never silently enter the array.","Re-check after Resources.UnloadUnusedAssets or domain reloads."],"tags":["sprite-atlas","argument-null","array-element","editor","csharp"],"backgroundTag":null,"analyzedSha":"225b0fbdb57cc17d094e8056b71f8314aba56f73","analyzedAt":"2026-08-13T19:07:19.849Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}