Unity-Technologies/UnityCsReference · error · ArgumentNullException
Parameter asset is null
Error message
Parameter asset is null
What it means
Thrown by SpriteAtlasAsset.Save when the asset argument is null. Save serializes exactly one SpriteAtlasAsset via InternalEditorUtility.SaveToSerializedFileAndForget, which requires a real object; a null asset cannot be wrapped in the Object[] passed to the serializer. The exception type is ArgumentNullException with a combined paramName/message.
Source
Thrown at Editor/Mono/2D/SpriteAtlas/SpriteAtlasAsset.bindings.cs:182
public void SetPackingSettings(SpriteAtlasPackingSettings src) { }
[Obsolete("GetPackingSettings is no longer supported and will be removed. Use SpriteAtlasImporter.GetPackingSettings instead.")]
public SpriteAtlasPackingSettings GetPackingSettings() { return new SpriteAtlasPackingSettings(); }
[Obsolete("GetTextureSettings is no longer supported and will be removed. Use SpriteAtlasImporter.GetTextureSettings instead.")]
public SpriteAtlasTextureSettings GetTextureSettings() { return new SpriteAtlasTextureSettings(); }
[Obsolete("GetPlatformSettings is no longer supported and will be removed. Use SpriteAtlasImporter.GetPlatformSettingss instead.")]
public TextureImporterPlatformSettings GetPlatformSettings(string buildTarget) { return new TextureImporterPlatformSettings(); }
// Load SpriteAtlasAsset
public static SpriteAtlasAsset Load(string assetPath)
{
var objs = UnityEditorInternal.InternalEditorUtility.LoadSerializedFileAndForget(assetPath);
return (objs.Length > 0) ? objs[0] as SpriteAtlasAsset : null;
}
public static void Save(SpriteAtlasAsset asset, string assetPath)
{
if (asset == null)
throw new ArgumentNullException("Parameter asset is null");
var objs = new UnityEngine.Object[] { asset };
UnityEditorInternal.InternalEditorUtility.SaveToSerializedFileAndForget(objs, assetPath, UnityEditor.EditorSettings.serializationMode != UnityEditor.SerializationMode.ForceBinary);
}
}
};
View on GitHub (pinned to 225b0fbdb5)
Solutions
- Check the result of SpriteAtlasAsset.Load for null before Save.
- Construct the SpriteAtlasAsset explicitly and confirm it is non-null before serializing.
- Wrap migration loops with a null guard that logs the offending path and continues.
- Validate assetPath exists with File.Exists before attempting Load+Save.
Example fix
// before
var asset = SpriteAtlasAsset.Load(srcPath);
SpriteAtlasAsset.Save(asset, dstPath);
// after
var asset = SpriteAtlasAsset.Load(srcPath);
if (asset == null) { Debug.LogError($"Failed to load atlas at {srcPath}"); return; }
SpriteAtlasAsset.Save(asset, dstPath); Defensive patterns
Strategy: validation
Validate before calling
if (asset == null) { Debug.LogError($"Cannot save: asset for {assetPath} is null (load failed?)."); return; } Prevention
- Check SpriteAtlasAsset.Load's return for null before Save.
- Validate the source path exists with File.Exists before loading.
- In batch migrations, log the offending path and continue rather than aborting.
When it happens
Trigger: Calling SpriteAtlasAsset.Save(null, path). Passing a SpriteAtlasAsset that failed to load (Load returned null) straight into Save. Creating a new asset via 'new SpriteAtlasAsset()' through an API that returned null on failure.
Common situations: Editor scripts that clone or migrate .spriteatlas files, where the source Load returned null (missing/corrupt file) but the script proceeded to Save. Batch conversion tooling that iterates many paths and does not check Load's null return.
Related errors
- Value for parameter atlases is null
- One of the elements in atlases is null. Please check your In
- gameObject
- bindings must be non-null
- keyframes must be non-null
AI-assisted analysis of Unity-Technologies/UnityCsReference@225b0fbdb5 (2026-08-13).
Data as JSON: /api/errors/fdb9dc33db0c4a65.
Report an issue: GitHub.