{"record":{"id":"fdb9dc33db0c4a65","repo":"Unity-Technologies/UnityCsReference","slug":"parameter-asset-is-null","errorCode":null,"errorMessage":"Parameter asset is null","messagePattern":"Parameter asset is null","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"Editor/Mono/2D/SpriteAtlas/SpriteAtlasAsset.bindings.cs","lineNumber":182,"sourceCode":"        public void SetPackingSettings(SpriteAtlasPackingSettings src) { }\n        [Obsolete(\"GetPackingSettings is no longer supported and will be removed. Use SpriteAtlasImporter.GetPackingSettings instead.\")]\n        public SpriteAtlasPackingSettings GetPackingSettings() { return new SpriteAtlasPackingSettings(); }\n        [Obsolete(\"GetTextureSettings is no longer supported and will be removed. Use SpriteAtlasImporter.GetTextureSettings instead.\")]\n        public SpriteAtlasTextureSettings GetTextureSettings() { return new SpriteAtlasTextureSettings(); }\n        [Obsolete(\"GetPlatformSettings is no longer supported and will be removed. Use SpriteAtlasImporter.GetPlatformSettingss instead.\")]\n        public TextureImporterPlatformSettings GetPlatformSettings(string buildTarget) { return new TextureImporterPlatformSettings(); }\n\n        // Load SpriteAtlasAsset\n        public static SpriteAtlasAsset Load(string assetPath)\n        {\n            var objs = UnityEditorInternal.InternalEditorUtility.LoadSerializedFileAndForget(assetPath);\n            return (objs.Length > 0) ? objs[0] as SpriteAtlasAsset : null;\n        }\n\n        public static void Save(SpriteAtlasAsset asset, string assetPath)\n        {\n            if (asset == null)\n                throw new ArgumentNullException(\"Parameter asset is null\");\n            var objs = new UnityEngine.Object[] { asset };\n            UnityEditorInternal.InternalEditorUtility.SaveToSerializedFileAndForget(objs, assetPath, UnityEditor.EditorSettings.serializationMode != UnityEditor.SerializationMode.ForceBinary);\n        }\n    }\n};\n","sourceCodeStart":164,"sourceCodeEnd":188,"githubUrl":"https://github.com/Unity-Technologies/UnityCsReference/blob/225b0fbdb57cc17d094e8056b71f8314aba56f73/Editor/Mono/2D/SpriteAtlas/SpriteAtlasAsset.bindings.cs#L164-L188","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nvar asset = SpriteAtlasAsset.Load(srcPath);\nSpriteAtlasAsset.Save(asset, dstPath);\n\n// after\nvar asset = SpriteAtlasAsset.Load(srcPath);\nif (asset == null) { Debug.LogError($\"Failed to load atlas at {srcPath}\"); return; }\nSpriteAtlasAsset.Save(asset, dstPath);","handlingStrategy":"validation","validationCode":"if (asset == null) { Debug.LogError($\"Cannot save: asset for {assetPath} is null (load failed?).\"); return; }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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."],"tags":["sprite-atlas","argument-null","serialization","editor","csharp"],"backgroundTag":null,"analyzedSha":"225b0fbdb57cc17d094e8056b71f8314aba56f73","analyzedAt":"2026-08-13T19:07:19.849Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}