Unity-Technologies/UnityCsReference · error · ArgumentException
Invalid material folder path: {0}.
Error message
Invalid material folder path: {0}. What it means
SpeedTree9Importer.SearchAndRemapMaterials throws ArgumentException with message 'Invalid material folder path: {0}.' when materialFolderPath is empty (but not null — null is caught by error 37's ArgumentNullException). The empty-path guard runs after the null check and before AssetDatabase.FindAssets, because FindAssets with an empty search folder would return unpredictable results. The interpolated message includes the offending path for debugging.
Source
Thrown at Editor/Mono/AssetPipeline/SpeedTree/SpeedTree9Importer.cs:1115
{
material.SetFloat(MaterialProperties.WindRippleKwToggle, 1.0f);
if (windCfg.doShimmer != 0)
{
material.SetFloat(MaterialProperties.WindShimmerKwToggle, 1.0f);
}
}
}
}
internal bool SearchAndRemapMaterials(string materialFolderPath)
{
bool changedMappings = false;
if (materialFolderPath == null)
throw new ArgumentNullException("materialFolderPath");
if (string.IsNullOrEmpty(materialFolderPath))
throw new ArgumentException(string.Format("Invalid material folder path: {0}.", materialFolderPath), "materialFolderPath");
string[] guids = AssetDatabase.FindAssets("t:Material", new string[] { materialFolderPath });
List<Tuple<string, Material>> materials = new List<Tuple<string, Material>>();
foreach (string guid in guids)
{
string path = AssetDatabase.GUIDToAssetPath(guid);
// ensure that we only load material assets, not embedded materials
Material material = AssetDatabase.LoadMainAssetAtPath(path) as Material;
if (material)
materials.Add(new Tuple<string, Material>(path, material));
}
m_OutputImporterData = AssetDatabase.LoadAssetAtPath<SpeedTreeImporterOutputData>(assetPath);
AssetIdentifier[] importedMaterials = m_OutputImporterData.materialsIdentifiers.ToArray();
foreach (Tuple<string, Material> material in materials)
{
string materialName = material.Item2.name;View on GitHub (pinned to 225b0fbdb5)
Solutions
- Check string.IsNullOrEmpty(materialFolderPath) before calling to catch both null and empty.
- Provide a default folder path (the asset's own directory or 'Assets/') when the field is empty.
- Disable the remap button in the inspector UI when the folder path is empty.
Example fix
// before
importer.SearchAndRemapMaterials(folderPath);
// after
if (!string.IsNullOrEmpty(folderPath))
importer.SearchAndRemapMaterials(folderPath);
else
Debug.LogWarning("SpeedTree material folder path is empty; set a valid folder before remapping"); Defensive patterns
Strategy: validation
Validate before calling
if (!string.IsNullOrEmpty(materialFolderPath))
importer.SearchAndRemapMaterials(materialFolderPath);
else
Debug.LogWarning("SpeedTree material folder path is empty; set a valid folder"); Type guard
static bool IsValidFolderPath(string path) => !string.IsNullOrEmpty(path);
Try / catch
try { importer.SearchAndRemapMaterials(folderPath); }
catch (ArgumentException ex) when (ex.Message.StartsWith("Invalid material folder path"))
{ Debug.LogWarning($"Cannot remap: {ex.Message}"); } Prevention
- Disable the remap UI action when the folder path is empty
- Provide a default folder (asset directory) when the field is unset
- Use string.IsNullOrEmpty to catch both null and empty before calling remap
When it happens
Trigger: Calling SearchAndRemapMaterials("") where the path is an empty string. This happens when a folder path field is set to empty by a UI reset, a serialization migration, or a user clearing the folder field in the inspector.
Common situations: SpeedTree importer inspector workflows where the user clears or never sets the external material folder path. Also occurs after reimporting SpeedTree assets from projects where the material folder setting was not preserved.
Related errors
AI-assisted analysis of Unity-Technologies/UnityCsReference@225b0fbdb5 (2026-08-13).
Data as JSON: /api/errors/cd0b4f1137dea6ff.
Report an issue: GitHub.