Unity-Technologies/UnityCsReference · error · ArgumentNullException
materialFolderPath
Error message
materialFolderPath
What it means
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).
Source
Thrown at Editor/Mono/AssetPipeline/SpeedTree/SpeedTree9Importer.cs:1112
material.SetFloat(MaterialProperties.WindBranch1KwToggle, 1.0f);
}
if (windCfg.doRipple != 0)
{
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();
View on GitHub (pinned to 225b0fbdb5)
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.
Example fix
// before
importer.SearchAndRemapMaterials(materialFolder);
// after
if (!string.IsNullOrEmpty(materialFolder))
importer.SearchAndRemapMaterials(materialFolder);
else
Debug.LogWarning("Cannot remap SpeedTree materials: folder path is null or empty"); Defensive patterns
Strategy: validation
Validate before calling
if (!string.IsNullOrEmpty(materialFolderPath))
importer.SearchAndRemapMaterials(materialFolderPath);
else
Debug.LogWarning("SpeedTree material folder path is null or empty"); Type guard
static bool IsValidFolderPath(string path) => !string.IsNullOrEmpty(path);
Try / catch
try { importer.SearchAndRemapMaterials(folderPath); }
catch (ArgumentNullException ex) when (ex.ParamName == "materialFolderPath")
{ Debug.LogWarning($"Cannot remap: {ex.Message}"); } Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Invalid material folder path: {0}.
- asset
- Cannot add dependency on invalid path.
- Cannot add source dependency on empty GUID.
- Cannot add artifact dependency on empty GUID.
AI-assisted analysis of Unity-Technologies/UnityCsReference@225b0fbdb5 (2026-08-13).
Data as JSON: /api/errors/6b60fe403d789abf.
Report an issue: GitHub.