{"record":{"id":"cbcb90a6f9071e02","repo":"Unity-Technologies/UnityCsReference","slug":"materialfolderpath-cbcb90","errorCode":null,"errorMessage":"materialFolderPath","messagePattern":"materialFolderPath","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"Editor/Mono/AssetPipeline/SpeedTreeImporter.bindings.cs","lineNumber":219,"sourceCode":"        {\n            [NativeName(\"MaterialsShouldBeRegenerated\")]\n            get;\n        }\n\n        internal extern void SetMaterialVersionToCurrent();\n\n        internal extern SourceAssetIdentifier[] sourceMaterials\n        {\n            [FreeFunction(Name = \"SpeedTreeImporterBindings::GetSourceMaterials\", HasExplicitThis = true)]\n            get;\n        }\n\n        public bool SearchAndRemapMaterials(string materialFolderPath)\n        {\n            bool changedMappings = false;\n\n            if (materialFolderPath == null)\n                throw new ArgumentNullException(\"materialFolderPath\");\n\n            if (string.IsNullOrEmpty(materialFolderPath))\n                throw new ArgumentException(string.Format(\"Invalid material folder path: {0}.\", materialFolderPath), \"materialFolderPath\");\n\n            var guids = AssetDatabase.FindAssets(\"t:Material\", new string[] { materialFolderPath });\n            List<Tuple<string, Material>> materials = new List<Tuple<string, Material>>();\n            foreach (var guid in guids)\n            {\n                var path = AssetDatabase.GUIDToAssetPath(guid);\n                // ensure that we only load material assets, not embedded materials\n                var material = AssetDatabase.LoadMainAssetAtPath(path) as Material;\n                if (material)\n                    materials.Add(new Tuple<string, Material>(path, material));\n            }\n\n            var importedMaterials = sourceMaterials;\n            foreach (var material in materials)\n            {","sourceCodeStart":201,"sourceCodeEnd":237,"githubUrl":"https://github.com/Unity-Technologies/UnityCsReference/blob/225b0fbdb57cc17d094e8056b71f8314aba56f73/Editor/Mono/AssetPipeline/SpeedTreeImporter.bindings.cs#L201-L237","documentation":"SpeedTreeImporter.SearchAndRemapMaterials(string materialFolderPath) walks a folder for Material assets and remaps them onto the importer's source materials. A null path is rejected up front with ArgumentNullException because AssetDatabase.FindAssets would otherwise throw a less specific NullReferenceException internally. The path is the search root, so null is always a programmer error, never a valid 'search everywhere' sentinel.","triggerScenarios":"Calling SearchAndRemapMaterials(null); passing a path variable that was never initialized or came from a null config field; a UI text field bound to the argument with no value entered.","commonSituations":"Editor tooling that drives remapping from a project setting that is unset; scripts that derive the folder from selection when nothing is selected; migration where the expected folder constant was removed.","solutions":["Pass an explicit material folder path string such as \"Assets/MyProject/Materials\".","If the folder is optional, branch on null before calling and skip/search a default location instead.","Validate the path at the UI/setting layer so a null never reaches the API."],"exampleFix":"// before\nimporter.SearchAndRemapMaterials(materialFolder); // materialFolder may be null\n\n// after\nif (string.IsNullOrEmpty(materialFolder))\n    throw new InvalidOperationException(\"Material folder not configured.\");\nimporter.SearchAndRemapMaterials(materialFolder);","handlingStrategy":"validation","validationCode":"if (materialFolderPath == null)\n    throw new InvalidOperationException(\"materialFolderPath not set\");\nimporter.SearchAndRemapMaterials(materialFolderPath);","typeGuard":"static bool IsUsableFolderPath(string p) => p != null;","tryCatchPattern":null,"preventionTips":["Bind editor fields to a non-null default folder constant.","When deriving the folder from selection, handle the nothing-selected case explicitly.","Surface unset configuration at the settings UI rather than at the API call."],"tags":["unity","speedtree","argument-validation","null-check","asset-database"],"backgroundTag":null,"analyzedSha":"225b0fbdb57cc17d094e8056b71f8314aba56f73","analyzedAt":"2026-08-13T19:07:19.849Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}