ArgumentNullException: Value for parameter atlases is null

The stack trace surfaces inside an editor batch routine the moment it reaches the atlas packing call, usually after a folder scan came back empty. The batch was meant to collect every SpriteAtlas under Assets/Art/Atlases and repack them for the current build target, but the filter matched zero assets, so the collection reference still held its default null value when the code jumped straight to SpriteAtlasUtility.PackAtlases(atlases, target).

ArgumentNullException: Value for parameter atlases is null 

Where the null is rejected

The guard lives in Editor/Mono/2D/SpriteAtlas/EditorSpriteAtlas.bindings.cs:28. On entry to PackAtlases, the binding checks the atlases argument first; when it finds atlases == null, it throws ArgumentNullException("atlases", ...) before touching any atlas, any texture, or the packing pipeline itself. No partial pack is produced, and the exception aborts the menu callback at the first frame of work. Upstream source, plain text: https://raw.githubusercontent.com/Unity-Technologies/UnityCsReference/master/Editor/Mono/2D/SpriteAtlas/EditorSpriteAtlas.bindings.cs#L28

Fix it in three steps

  1. Hand over an initialized array, never a null reference. Build the SpriteAtlas[] from a populated list; a freshly constructed empty list converted to an array is legal input, while an uninitialized reference is not.
var collected = new List<SpriteAtlas>(); // ...fill collected from scanned assets... SpriteAtlas[] atlases = collected.ToArray(); 
  1. Check the collection before the packing call. Guard for both a null list and a zero-length result, and exit with a clear log when nothing was found instead of letting the exception escape into the Console.
if (atlases == null || atlases.Length == 0) { Debug.LogWarning("Atlas list is empty; packing step aborted."); return; } 
  1. Load each atlas resource before it enters the batch. Confirm the collected path resolves through AssetDatabase.LoadAssetAtPath so the reference on the array points at a real, imported SpriteAtlas rather than a missing or unloaded asset.

The complete editor script below collects atlases from a fixed folder, drops null loads, guards the empty case, and only then calls the packing utility:

using System.Collections.Generic; using UnityEditor; using UnityEngine; using UnityEngine.U2D; public static class AtlasPackerBatch { private const string AtlasFolder = "Assets/Art/Atlases"; [MenuItem("Tools/Atlas/Pack Collected Atlases")] public static void PackCollected() { var atlases = new List<SpriteAtlas>(); string[] guids = AssetDatabase.FindAssets("t:SpriteAtlas", new[] { AtlasFolder }); foreach (string guid in guids) { string path = AssetDatabase.GUIDToAssetPath(guid); SpriteAtlas loaded = AssetDatabase.LoadAssetAtPath<SpriteAtlas>(path); if (loaded != null) atlases.Add(loaded); } if (atlases == null || atlases.Count == 0) { Debug.LogWarning("No SpriteAtlas assets were collected; packing skipped."); return; } SpriteAtlas[] atlasArray = atlases.ToArray(); SpriteAtlasUtility.PackAtlases(atlasArray, EditorUserBuildSettings.activeBuildTarget); } } 

Batch guard checklist

Pipeline point Failure mode Guard to add
Folder scan Filter matches zero assets Log the empty result and stop before packing
Array hand-off Reference left uninitialized Convert a populated list into the array
Asset loading Collected path fails to resolve Call LoadAssetAtPath and skip null entries
Pack entry Null array reaches PackAtlases Null and length check ahead of the utility call

Run the free inspector against your editor batch to spot collection paths that feed null into packing calls: https://atlas-errors.petersoncool.workers.dev/inspector/?ref=dev2_free_6

The complete batch-repair bundle covers scan filters, null-safe helpers, and repack workflows for multi-atlas projects: https://atlas-errors.petersoncool.workers.dev/checkout/?ref=dev2_buy_6