{"record":{"id":"6b60fe403d789abf","repo":"Unity-Technologies/UnityCsReference","slug":"materialfolderpath","errorCode":null,"errorMessage":"materialFolderPath","messagePattern":"materialFolderPath","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"Editor/Mono/AssetPipeline/SpeedTree/SpeedTree9Importer.cs","lineNumber":1112,"sourceCode":"                    material.SetFloat(MaterialProperties.WindBranch1KwToggle, 1.0f);\n                }\n                if (windCfg.doRipple != 0)\n                {\n                    material.SetFloat(MaterialProperties.WindRippleKwToggle, 1.0f);\n                    if (windCfg.doShimmer != 0)\n                    {\n                        material.SetFloat(MaterialProperties.WindShimmerKwToggle, 1.0f);\n                    }\n                }\n            }\n        }\n\n        internal 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            string[] guids = AssetDatabase.FindAssets(\"t:Material\", new string[] { materialFolderPath });\n            List<Tuple<string, Material>> materials = new List<Tuple<string, Material>>();\n            foreach (string guid in guids)\n            {\n                string path = AssetDatabase.GUIDToAssetPath(guid);\n                // ensure that we only load material assets, not embedded materials\n                Material material = AssetDatabase.LoadMainAssetAtPath(path) as Material;\n                if (material)\n                    materials.Add(new Tuple<string, Material>(path, material));\n            }\n\n            m_OutputImporterData = AssetDatabase.LoadAssetAtPath<SpeedTreeImporterOutputData>(assetPath);\n            AssetIdentifier[] importedMaterials = m_OutputImporterData.materialsIdentifiers.ToArray();\n","sourceCodeStart":1094,"sourceCodeEnd":1130,"githubUrl":"https://github.com/Unity-Technologies/UnityCsReference/blob/225b0fbdb57cc17d094e8056b71f8314aba56f73/Editor/Mono/AssetPipeline/SpeedTree/SpeedTree9Importer.cs#L1094-L1130","documentation":"SpeedTree9Importer.SearchAndRemapMaterials(string materialFolderPath) searches for materials at the given folder path and remaps them to SpeedTree material slots. It throws ArgumentNullException with param name 'materialFolderPath' when the argument is null. This is the first of two guards: null triggers ArgumentNullException, empty triggers ArgumentException (error 38).","triggerScenarios":"Calling SearchAndRemapMaterials(null) directly, or passing a path field that was never initialized. Since this is an internal method, it is typically called by the SpeedTree9Importer's remap UI or serialization logic, not directly by user code.","commonSituations":"SpeedTree material remap operations triggered from the importer inspector, where the material folder path comes from a serialized field that is null due to uninitialized state, a reset, or a migration from an older SpeedTree importer version.","solutions":["Ensure materialFolderPath is non-null before calling: if (materialFolderPath != null) SearchAndRemapMaterials(materialFolderPath).","Initialize the folder path field to a sensible default (e.g., the asset's directory) rather than leaving it null.","Validate the path comes from a properly serialized importer state before invoking remap."],"exampleFix":"// before\nimporter.SearchAndRemapMaterials(materialFolder);\n\n// after\nif (!string.IsNullOrEmpty(materialFolder))\n    importer.SearchAndRemapMaterials(materialFolder);\nelse\n    Debug.LogWarning(\"Cannot remap SpeedTree materials: folder path is null or empty\");","handlingStrategy":"validation","validationCode":"if (!string.IsNullOrEmpty(materialFolderPath))\n    importer.SearchAndRemapMaterials(materialFolderPath);\nelse\n    Debug.LogWarning(\"SpeedTree material folder path is null or empty\");","typeGuard":"static bool IsValidFolderPath(string path) => !string.IsNullOrEmpty(path);","tryCatchPattern":"try { importer.SearchAndRemapMaterials(folderPath); }\ncatch (ArgumentNullException ex) when (ex.ParamName == \"materialFolderPath\")\n{ Debug.LogWarning($\"Cannot remap: {ex.Message}\"); }","preventionTips":["Initialize SpeedTree material folder paths to the asset's directory","Validate the folder path field is set before triggering remap","Guard with string.IsNullOrEmpty to cover both null and empty"],"tags":["unity","csharp","asset-pipeline","speedtree","material-remap","null-check"],"backgroundTag":null,"analyzedSha":"225b0fbdb57cc17d094e8056b71f8314aba56f73","analyzedAt":"2026-08-13T19:07:19.849Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}