{"record":{"id":"836c9e933647ef18","repo":"Unity-Technologies/UnityCsReference","slug":"asset","errorCode":null,"errorMessage":"asset","messagePattern":"asset","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"Editor/Mono/AssetPipeline/AssetImporter.bindings.cs","lineNumber":31,"sourceCode":"using UnityEditor.Experimental;\n\nnamespace UnityEditor\n{\n    [NativeHeader(\"Editor/Src/AssetPipeline/AssetImporter.h\")]\n    [NativeHeader(\"Editor/Src/AssetPipeline/AssetImporter.bindings.h\")]\n    [ExcludeFromObjectFactory]\n    [Preserve]\n    [global::UnityEngine.NativeClass(\"AssetImporter\", PersistentTypeId = 1003)]\n    [UsedByNativeCode]\n    public partial class AssetImporter : Object\n    {\n        public struct SourceAssetIdentifier\n        {\n            public SourceAssetIdentifier(Object asset)\n            {\n                if (asset == null)\n                {\n                    throw new ArgumentNullException(\"asset\");\n                }\n\n                this.type = asset.GetType();\n                this.name = asset.name;\n            }\n\n            public SourceAssetIdentifier(Type type, string name)\n            {\n                if (type == null)\n                {\n                    throw new ArgumentNullException(\"type\");\n                }\n\n                if (name == null)\n                {\n                    throw new ArgumentNullException(\"name\");\n                }\n","sourceCodeStart":13,"sourceCodeEnd":49,"githubUrl":"https://github.com/Unity-Technologies/UnityCsReference/blob/225b0fbdb57cc17d094e8056b71f8314aba56f73/Editor/Mono/AssetPipeline/AssetImporter.bindings.cs#L13-L49","documentation":"AssetImporter.SourceAssetIdentifier(Object asset) constructor creates an identifier from a Unity Object's type and name. It throws ArgumentNullException with param name 'asset' when the passed Object is null, because it needs asset.GetType() and asset.name to populate the struct. SourceAssetIdentifier is used to map sub-assets within an importer (e.g., remapping materials or meshes in model importers).","triggerScenarios":"Constructing new SourceAssetIdentifier(obj) where obj is null. This happens when loading a sub-asset via AssetDatabase.LoadAssetAtPath returns null (asset not found, wrong type, or not yet imported) and the null is passed directly to the constructor without a null check.","commonSituations":"Model importer remapping code, material remap utilities, or editor scripts that build SourceAssetIdentifier lists from loaded assets. The null arises from failed asset loads, type mismatches in 'as' casts, or assets that haven't been imported yet at the time of the call.","solutions":["Null-check before constructing: if (obj != null) new SourceAssetIdentifier(obj).","Use the (Type, string) overload instead if you already know the type and name, avoiding the Object dependency.","Validate the loaded asset's type matches expectations before passing to the constructor."],"exampleFix":"// before\nvar id = new SourceAssetIdentifier(loadedAsset);\n\n// after\nif (loadedAsset != null)\n    var id = new SourceAssetIdentifier(loadedAsset);\nelse\n    Debug.LogWarning(\"Cannot create SourceAssetIdentifier: asset is null\");","handlingStrategy":"validation","validationCode":"if (asset != null)\n    var id = new AssetImporter.SourceAssetIdentifier(asset);\nelse\n    Debug.LogWarning(\"Cannot create SourceAssetIdentifier: null asset\");","typeGuard":"static bool IsValidUnityObject(Object obj) => obj != null;","tryCatchPattern":"try { var id = new AssetImporter.SourceAssetIdentifier(asset); }\ncatch (ArgumentNullException ex) when (ex.ParamName == \"asset\")\n{ Debug.LogWarning($\"Skipped SourceAssetIdentifier: {ex.Message}\"); }","preventionTips":["Null-check loaded assets before constructing SourceAssetIdentifier","Validate 'as' cast results before passing to constructors","Use the (Type, string) overload when you have type/name without the Object"],"tags":["unity","csharp","asset-pipeline","asset-importer","source-asset-identifier","null-check"],"backgroundTag":null,"analyzedSha":"225b0fbdb57cc17d094e8056b71f8314aba56f73","analyzedAt":"2026-08-13T19:07:19.849Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}