Unity-Technologies/UnityCsReference · error · ArgumentException

For the '{0}' target the 'locationPathName' parameter for Bu

Error message

For the '{0}' target the 'locationPathName' parameter for BuildPipeline.BuildPlayer should not end with a directory separator.
Provided path: '{1}', expected a path with the extension '.{2}'.

What it means

ArgumentException thrown by BuildPipeline.BuildPlayer when ValidateLocationPathNameForBuildTarget rejects the locationPathName because it ends with a directory separator character (indicating a folder path rather than a file path) or does not have the expected file extension for the target platform. The message is a format string with the target name, provided path, and expected extension as parameters.

Source

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

        ///
        ///It also means that the built-in scripting symbols defined for the current active target platform (such as UNITY_STANDALONE_WIN, or UNITY_ANDROID) remain in place even if you try to build for a different target platform, which can result in the wrong code being compiled into your build.</remarks>
        ///<param name="buildPlayerOptions">Provide various options to control the behavior of <see cref="BuildPipeline.BuildPlayer" />.</param>
        ///<returns>A <see cref="BuildReport" /> object containing build process information.</returns>
        ///<example>
        ///  <code source="../../../Modules/ContentBuild/Tests/local.test.build-examples/Editor/BuildPipeline/BuildPipeline_BuildPlayer.cs"/>
        ///</example>
        ///<seealso cref="BuildPlayerWindow.DefaultBuildMethods.BuildPlayer" />
        public static BuildReport BuildPlayer(BuildPlayerOptions buildPlayerOptions)
        {
            if (isBuildingPlayer)
                throw new InvalidOperationException("Cannot start a new build because there is already a build in progress.");

            if (buildPlayerOptions.targetGroup == BuildTargetGroup.Unknown)
                buildPlayerOptions.targetGroup = GetBuildTargetGroup(buildPlayerOptions.target);

            string locationPathNameError;
            if (!ValidateLocationPathNameForBuildTarget(buildPlayerOptions.locationPathName, buildPlayerOptions.target, buildPlayerOptions.subtarget, buildPlayerOptions.options, out locationPathNameError))
                throw new ArgumentException(locationPathNameError);

            string scenesError;
            if (!ValidateScenePaths(buildPlayerOptions.scenes, out scenesError))
                throw new ArgumentException(scenesError);

            if ((buildPlayerOptions.options & BuildOptions.AcceptExternalModificationsToPlayer) == BuildOptions.AcceptExternalModificationsToPlayer)
            {
                CanAppendBuild canAppend = BuildCanBeAppended(buildPlayerOptions.target, buildPlayerOptions.locationPathName);
                if (canAppend == CanAppendBuild.Unsupported)
                    throw new InvalidOperationException("The build target does not support build appending.");
                if (canAppend == CanAppendBuild.No)
                    throw new InvalidOperationException("The build cannot be appended.");
            }

            if (buildPlayerOptions.scenes != null)
            {
                for (int i = 0; i < buildPlayerOptions.scenes.Length; i++)
                    buildPlayerOptions.scenes[i] = buildPlayerOptions.scenes[i].Replace('\\', '/').Replace("//", "/");

View on GitHub (pinned to 225b0fbdb5)

Solutions

  1. Provide a full file path with the correct extension for the target platform (e.g. .exe for Windows, .app for macOS, .apk for Android).
  2. Ensure the path does not end with a directory separator.
  3. Use platform-aware path construction: append the correct extension based on BuildTarget.
  4. Check the error message for the expected extension and adjust the path accordingly.

Example fix

// before
options.locationPathName = "Build/MyGame/"; // ends with separator
// or
options.locationPathName = "Build/MyGame"; // no extension
// after — platform-appropriate file path with extension
options.locationPathName = BuildTarget == BuildTarget.StandaloneWindows64
    ? "Build/MyGame/MyGame.exe"
    : BuildTarget == BuildTarget.StandaloneOSX
        ? "Build/MyGame/MyGame.app"
        : "Build/MyGame/MyGame.apk";
Defensive patterns

Strategy: validation

Validate before calling

// Validate locationPathName format for the target platform
string GetExpectedExtension(BuildTarget target)
{
    switch (target)
    {
        case BuildTarget.StandaloneWindows:
        case BuildTarget.StandaloneWindows64:
            return ".exe";
        case BuildTarget.StandaloneOSX:
            return ".app";
        case BuildTarget.Android:
            return ".apk";
        default:
            return "";
    }
}

string expected = GetExpectedExtension(buildPlayerOptions.target);
if (string.IsNullOrEmpty(expected) || !buildPlayerOptions.locationPathName.EndsWith(expected))
{
    Debug.LogError($"locationPathName must end with '{expected}' for {buildPlayerOptions.target}.");
    return;
}
if (buildPlayerOptions.locationPathName.EndsWith("/") || buildPlayerOptions.locationPathName.EndsWith("\\"))
{
    Debug.LogError("locationPathName must not end with a directory separator.");
    return;
}
BuildPipeline.BuildPlayer(buildPlayerOptions);

Prevention

When it happens

Trigger: Calling BuildPipeline.BuildPlayer with a locationPathName that ends in '/' or '\\' (e.g. "Build/") or that lacks the correct extension for the target (e.g. "Build/app" instead of "Build/app.exe" for Windows, "Build/app.app" for macOS, "Build/app.apk" for Android). The validation function checks the path against platform-specific expectations.

Common situations: Scripts that set locationPathName to a directory path instead of a file path, platform-switching build scripts that reuse a generic path without adjusting the extension, CI configs that specify output folders rather than output files, cross-platform path handling that drops the extension.

Related errors


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