Unity-Technologies/UnityCsReference · error · ArgumentException
The 'locationPathName' parameter for BuildPipeline.BuildPlay
Error message
The 'locationPathName' parameter for BuildPipeline.BuildPlayer should not be null or empty.
What it means
ArgumentException thrown by BuildPipeline.BuildPlayer when ValidateLocationPathNameForBuildTarget rejects the locationPathName because it is null or empty. The output path is required so the build system knows where to write the player binary; an empty path makes the build destination ambiguous.
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
- Set buildPlayerOptions.locationPathName to a valid output path before calling BuildPlayer.
- Validate the path is non-empty: if (string.IsNullOrEmpty(options.locationPathName)) { /* handle */ }
- If reading the path from configuration, verify the config field exists and is non-empty.
- Use platform-appropriate path construction (e.g. Path.Combine) to avoid empty segments.
Example fix
// before
var options = new BuildPlayerOptions
{
scenes = new[] { "Assets/Scenes/Main.unity" },
target = BuildTarget.StandaloneWindows64,
// locationPathName missing!
};
BuildPipeline.BuildPlayer(options);
// after
var options = new BuildPlayerOptions
{
scenes = new[] { "Assets/Scenes/Main.unity" },
locationPathName = "Build/MyGame.exe",
target = BuildTarget.StandaloneWindows64,
};
BuildPipeline.BuildPlayer(options); Defensive patterns
Strategy: validation
Validate before calling
// Validate locationPathName before calling BuildPlayer
if (string.IsNullOrEmpty(buildPlayerOptions.locationPathName))
{
Debug.LogError("locationPathName must not be null or empty.");
return;
}
BuildPipeline.BuildPlayer(buildPlayerOptions); Type guard
static bool HasValidOutputPath(BuildPlayerOptions options)
=> !string.IsNullOrEmpty(options?.locationPathName); Prevention
- Always set locationPathName to a concrete output file path.
- Validate path strings from config files before passing to BuildPlayer.
- Use Path.Combine to construct paths and verify the result is non-empty.
- Default to a sensible output path in build scripts to avoid accidental null.
When it happens
Trigger: Calling BuildPipeline.BuildPlayer with buildPlayerOptions.locationPathName set to null, empty string, or whitespace. Occurs when scripts construct BuildPlayerOptions without setting the output path, when the path is read from a config that omits it, or when path-building string operations produce an empty result.
Common situations: Build scripts that forget to set locationPathName, CI config files with missing or commented-out output path fields, dynamic path construction where variables resolve to empty strings, platform-specific path logic that returns empty for an unsupported subtarget.
Related errors
- For the '{0}' target the 'locationPathName' parameter for Bu
- Build profile is invalid.
- Must be greater than zero.
- clips
- Must not be empty.
AI-assisted analysis of Unity-Technologies/UnityCsReference@225b0fbdb5 (2026-08-13).
Data as JSON: /api/errors/62820fa491f7d22c.
Report an issue: GitHub.