Unity-Technologies/UnityCsReference · error · ArgumentException

Invalid build path: '{buildPlayerOptions.locationPathName}'.

Error message

Invalid build path: '{buildPlayerOptions.locationPathName}'. {msg}

What it means

Thrown when BuildPlayerWindow.DefaultBuildMethods.IsBuildPathValid rejects the locationPathName. The validation checks that the output path is well-formed, writable, and appropriate for the target platform (e.g., extension matching, not pointing at a system directory). The interpolated msg carries the specific reason returned by IsBuildPathValid.

Source

Thrown at Editor/Mono/BuildPipeline/BuildPipeline.bindings.cs:264

                if ((buildPlayerOptions.options & BuildOptions.ConnectWithProfiler) != 0)
                {
                    throw new ArgumentException("Non-development build cannot allow auto-connecting the profiler. Either add the Development build option, or remove the ConnectWithProfiler build option.");
                }
            }
            else
            {
                if ((buildPlayerOptions.options & BuildOptions.EnableCodeCoverage) != 0)
                {
                    if (!BuildProfileModuleUtil.IsBuildTargetSupportedByCoverage(buildPlayerOptions.target))
                        throw new ArgumentException("Code coverage is unavailable for the selected build target. Remove the EnableCodeCoverage build option.");
                }
            }

            try
            {
                if (!BuildPlayerWindow.DefaultBuildMethods.IsBuildPathValid(buildPlayerOptions.locationPathName, out var msg))
                    throw new ArgumentException($"Invalid build path: '{buildPlayerOptions.locationPathName}'. {msg}");

                if (buildPlayerOptions.targetGroup == BuildTargetGroup.Standalone)
                {
                    if (buildPlayerOptions.subtarget == (int)StandaloneBuildSubtarget.Default)
                        buildPlayerOptions.subtarget = (int)EditorUserBuildSettings.standaloneBuildSubtarget;

                    EditorUserBuildSettings.standaloneBuildSubtarget = (StandaloneBuildSubtarget)buildPlayerOptions.subtarget;
                }

                return BuildPlayerInternal(
                    buildPlayerOptions.scenes,
                    buildPlayerOptions.locationPathName,
                    buildPlayerOptions.assetBundleManifestPath,
                    buildPlayerOptions.targetGroup,
                    buildPlayerOptions.target,
                    buildPlayerOptions.subtarget,
                    buildPlayerOptions.options,
                    buildPlayerOptions.extraScriptingDefines,

View on GitHub (pinned to 225b0fbdb5)

Solutions

  1. Read the interpolated msg in the exception to see the specific rejection reason and address it directly.
  2. Ensure the locationPathName extension matches the target platform (e.g., no extension or .app for macOS, .exe for Windows, a directory for Android/iOS).
  3. Use Path.GetFullPath to resolve relative paths and verify the parent directory exists and is writable before building.

Example fix

// before
var options = new BuildPlayerOptions
{
    locationPathName = "Build/game.exe",
    target = BuildTarget.StandaloneOSX
};
BuildPipeline.BuildPlayer(options);

// after
var options = new BuildPlayerOptions
{
    locationPathName = "Build/game.app",
    target = BuildTarget.StandaloneOSX
};
BuildPipeline.BuildPlayer(options);
Defensive patterns

Strategy: validation

Validate before calling

void ValidateBuildPath(string path, BuildTarget target)
{
    if (string.IsNullOrWhiteSpace(path))
        throw new ArgumentException("locationPathName is empty");

    string fullPath = Path.GetFullPath(path);
    string parent = Path.GetDirectoryName(fullPath);
    if (!string.IsNullOrEmpty(parent) && !Directory.Exists(parent))
        throw new ArgumentException($"Build parent directory does not exist: {parent}");

    // Platform-specific extension checks
    if (target == BuildTarget.StandaloneWindows64 && !fullPath.EndsWith(".exe"))
        throw new ArgumentException("Windows build path must end with .exe");
    if (target == BuildTarget.StandaloneOSX && !fullPath.EndsWith(".app"))
        throw new ArgumentException("macOS build path must end with .app");
}

// Before BuildPlayer:
ValidateBuildPath(options.locationPathName, options.target);

Prevention

When it happens

Trigger: Calling BuildPipeline.BuildPlayer with a locationPathName that is empty, contains illegal characters, has the wrong file extension for the target (e.g., .exe for Android), points to a read-only directory, or resolves to a protected system path.

Common situations: Build scripts using a relative path that resolves incorrectly when run from different working directories, wrong file extension for the platform (e.g., '.exe' for macOS or '.app' for Windows), path containing environment variables that aren't expanded, or a path inside the Assets/ folder.

Related errors


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