{"record":{"id":"e833be6c24f80257","repo":"Unity-Technologies/UnityCsReference","slug":"asset-e833be","errorCode":null,"errorMessage":"asset","messagePattern":"asset","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"Editor/Mono/AssetPipeline/SpeedTree/SpeedTreeImporterSettings.cs","lineNumber":143,"sourceCode":"        [Range(0.0f, 1.0f)]\n        public float randomness = 0.5f;\n    }\n\n    // Ideally, we should use 'AssetImporter.SourceAssetIdentifier', but this struct has many problems:\n    // 1 - 'Type' is not a serializable type, so it's always equal to null in our context.\n    // 2 - The C# struct is not matching the C++ class.\n    // 3 - Missing the 'Serializable' attribute on top of the struct.\n    [Serializable]\n    internal class AssetIdentifier\n    {\n        public string type;\n        public string name;\n\n        public AssetIdentifier(UnityEngine.Object asset)\n        {\n            if (asset == null)\n            {\n                throw new ArgumentNullException(\"asset\");\n            }\n\n            this.type = asset.GetType().ToString();\n            this.name = asset.name;\n        }\n\n        public AssetIdentifier(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":125,"sourceCodeEnd":161,"githubUrl":"https://github.com/Unity-Technologies/UnityCsReference/blob/225b0fbdb57cc17d094e8056b71f8314aba56f73/Editor/Mono/AssetPipeline/SpeedTree/SpeedTreeImporterSettings.cs#L125-L161","documentation":"SpeedTreeImporterSettings.AssetIdentifier(Object asset) constructor creates an identifier from a Unity Object's type and name for SpeedTree asset remapping. It throws ArgumentNullException with param name 'asset' when the passed Object is null, because it needs asset.GetType().ToString() and asset.name to populate the type and name fields. This mirrors the SourceAssetIdentifier pattern (error 33) but uses string type names instead of System.Type.","triggerScenarios":"Constructing new AssetIdentifier(obj) where obj is null. This happens when loading a material, mesh, or texture for SpeedTree remapping returns null due to a failed load, wrong type cast, or unimported asset, and the null is passed directly.","commonSituations":"SpeedTree material/geometry remap utilities, editor scripts that build AssetIdentifier lists from loaded sub-assets. The null arises from AssetDatabase.LoadAssetAtPath returning null on missing assets, type mismatches, or assets pending import.","solutions":["Null-check before constructing: if (asset != null) new AssetIdentifier(asset).","Use the (Type, string) overload if available and you have type/name without needing the Object.","Validate loaded assets with a null check and type check before constructing identifiers."],"exampleFix":"// before\nvar id = new AssetIdentifier(loadedMaterial);\n\n// after\nif (loadedMaterial != null)\n    var id = new AssetIdentifier(loadedMaterial);\nelse\n    Debug.LogWarning(\"Cannot create SpeedTree AssetIdentifier: asset is null\");","handlingStrategy":"validation","validationCode":"if (asset != null)\n    var id = new AssetIdentifier(asset);\nelse\n    Debug.LogWarning(\"Cannot create SpeedTree AssetIdentifier: null asset\");","typeGuard":"static bool IsValidUnityObject(Object obj) => obj != null;","tryCatchPattern":"try { var id = new AssetIdentifier(asset); }\ncatch (ArgumentNullException ex) when (ex.ParamName == \"asset\")\n{ Debug.LogWarning($\"Skipped AssetIdentifier: {ex.Message}\"); }","preventionTips":["Null-check all loaded materials/meshes/textures before constructing AssetIdentifier","Validate 'as' cast results (Material, Mesh) for null","Use the (Type, string) overload when the Object is unavailable"],"tags":["unity","csharp","asset-pipeline","speedtree","asset-identifier","null-check"],"backgroundTag":null,"analyzedSha":"225b0fbdb57cc17d094e8056b71f8314aba56f73","analyzedAt":"2026-08-13T19:07:19.849Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}