CoplayDev/unity-mcp · error · ArgumentException

Selected folder does not exist.

Error message

Selected folder does not exist.

What it means

Thrown by ValidateSource when sourcePath is non-empty but Directory.Exists returns false — the folder is not present on disk. This catches deleted/moved source folders and paths that never existed before deployment attempts to copy from them.

Source

Thrown at MCPForUnity/Editor/Services/PackageDeploymentService.cs:231

        }

        private static string ValidateSource(string sourcePath, bool throwOnError = true)
        {
            if (string.IsNullOrEmpty(sourcePath))
            {
                if (throwOnError)
                {
                    throw new ArgumentException("Source path cannot be empty.");
                }

                return "Source path is empty.";
            }

            if (!Directory.Exists(sourcePath))
            {
                if (throwOnError)
                {
                    throw new ArgumentException("Selected folder does not exist.");
                }

                return "Selected folder does not exist.";
            }

            bool hasEditor = Directory.Exists(Path.Combine(sourcePath, "Editor"));
            bool hasRuntime = Directory.Exists(Path.Combine(sourcePath, "Runtime"));

            if (!hasEditor || !hasRuntime)
            {
                string message = "Folder must contain Editor and Runtime subfolders.";
                if (throwOnError)
                {
                    throw new ArgumentException(message);
                }

                return message;
            }

View on GitHub (pinned to c21bf496bc)

Solutions

  1. Verify the folder exists on disk (Directory.Exists) before deploying.
  2. Re-select the folder in the UI picker, or pass a verified absolute path.
  3. If using a relative path, resolve it to absolute (Path.GetFullPath) first to confirm location.

Example fix

// before
ValidateSource(sourcePath, throwOnError: true); // throws if folder gone

// after
if (!Directory.Exists(sourcePath)) return Error($"Folder not found: {sourcePath}");
ValidateSource(sourcePath, throwOnError: true);
Defensive patterns

Strategy: validation

Validate before calling

if (!Directory.Exists(sourcePath))
    return ErrorResponse($"Source folder not found: {sourcePath}");
ValidateSource(sourcePath, throwOnError: true);

Type guard

static bool SourceFolderExists(string p) => !string.IsNullOrEmpty(p) && Directory.Exists(p);

Try / catch

try { ValidateSource(sourcePath, throwOnError: true); }
catch (ArgumentException ex) when (ex.Message.Contains("does not exist"))
{ /* re-pick the folder; it was moved/deleted */ }

Prevention

When it happens

Trigger: sourcePath points to a folder that was deleted, moved, or never created; a relative path resolved against an unexpected working directory; a typo in the path.

Common situations: Folder moved/deleted after being selected in the UI; relative path assuming the wrong cwd; path copied with a typo; external drive unmounted.

Related errors


AI-assisted analysis of CoplayDev/unity-mcp@c21bf496bc (2026-08-13). Data as JSON: /api/errors/47c7eace078388d5. Report an issue: GitHub.