Unity-Technologies/UnityCsReference · error · ArgumentException

Invalid material folder path: {0}.

Error message

Invalid material folder path: {0}.

What it means

The second guard in SearchAndRemapMaterials: after null is excluded, an empty path is also rejected because AssetDatabase.FindAssets with an empty folder would match everything (or nothing useful) and silently produce wrong remapping results. Note the message formats the path inline ("Invalid material folder path: {0}."), so for the empty-string case it renders as an empty path in the message.

Source

Thrown at Editor/Mono/AssetPipeline/SpeedTreeImporter.bindings.cs:222

        }

        internal extern void SetMaterialVersionToCurrent();

        internal extern SourceAssetIdentifier[] sourceMaterials
        {
            [FreeFunction(Name = "SpeedTreeImporterBindings::GetSourceMaterials", HasExplicitThis = true)]
            get;
        }

        public 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");

            var guids = AssetDatabase.FindAssets("t:Material", new string[] { materialFolderPath });
            List<Tuple<string, Material>> materials = new List<Tuple<string, Material>>();
            foreach (var guid in guids)
            {
                var path = AssetDatabase.GUIDToAssetPath(guid);
                // ensure that we only load material assets, not embedded materials
                var material = AssetDatabase.LoadMainAssetAtPath(path) as Material;
                if (material)
                    materials.Add(new Tuple<string, Material>(path, material));
            }

            var importedMaterials = sourceMaterials;
            foreach (var material in materials)
            {
                var materialName = material.Item2.name;
                var materialFile = material.Item1;

View on GitHub (pinned to 225b0fbdb5)

Solutions

  1. Provide a concrete folder under Assets/ (e.g. "Assets/Materials").
  2. Validate with !string.IsNullOrEmpty(materialFolderPath) and with AssetDatabase.IsValidFolder before calling.
  3. Strip/sanitize user-supplied paths and reject blanks at the UI layer.

Example fix

// before
importer.SearchAndRemapMaterials(folder);

// after
if (string.IsNullOrWhiteSpace(folder) || !AssetDatabase.IsValidFolder(folder))
    throw new InvalidOperationException("Invalid material folder: " + folder);
importer.SearchAndRemapMaterials(folder);
Defensive patterns

Strategy: validation

Validate before calling

if (string.IsNullOrWhiteSpace(materialFolderPath) || !AssetDatabase.IsValidFolder(materialFolderPath))
    throw new InvalidOperationException("Invalid material folder: " + materialFolderPath);
importer.SearchAndRemapMaterials(materialFolderPath);

Type guard

static bool IsValidFolder(string p) => !string.IsNullOrWhiteSpace(p) && AssetDatabase.IsValidFolder(p);

Prevention

When it happens

Trigger: Calling SearchAndRemapMaterials(""); passing a path that was trimmed to empty; a path built from string concatenation where one component was missing.

Common situations: Editor text field submitted empty; path derived from a parent folder constant that is empty; whitespace-only path that was trimmed.

Related errors


AI-assisted analysis of Unity-Technologies/UnityCsReference@225b0fbdb5 (2026-08-13). Data as JSON: /api/errors/3e0432b49a117eef. Report an issue: GitHub.