Unity-Technologies/UnityCsReference · error · BuildMethodException

Build location for buildTarget {buildTarget} is not valid.

Error message

Build location for buildTarget {buildTarget} is not valid.

What it means

During build-location resolution, if the user did not pick a location and EditorUserBuildSettings.GetBuildLocation(buildTarget) returns an empty string, the build aborts with BuildMethodException. An empty stored location means no valid output path is available for the target.

Source

Thrown at Editor/Mono/BuildPlayerWindowBuildMethods.cs:315

                        {
                            EditorUtility.DisplayDialog("Invalid build path", msg, "OK");
                            Debug.LogError($"Invalid build path: '{buildPath}'. {msg}");
                            throw new BuildMethodException();
                        }

                        if (BuildPipeline.BuildCanBeAppended(buildTarget, buildPath) == CanAppendBuild.Yes)
                            updateExistingBuild = true;
                    }
                    else
                    {
                        if (askForBuildLocation && !PickBuildLocation(buildTargetGroup, buildTarget, subtarget, options.options, out updateExistingBuild))
                            throw new BuildMethodException();

                        var newLocation = EditorUserBuildSettings.GetBuildLocation(buildTarget);

                        if (newLocation.Length == 0)
                        {
                            throw new BuildMethodException("Build location for buildTarget " + buildTarget + " is not valid.");
                        }

                        if (!askForBuildLocation)
                        {
                            switch (BuildPipeline.BuildCanBeAppended(buildTarget, newLocation))
                            {
                                case CanAppendBuild.Unsupported:
                                    break;
                                case CanAppendBuild.Yes:
                                    updateExistingBuild = true;
                                    break;
                                case CanAppendBuild.No:
                                    if (!PickBuildLocation(buildTargetGroup, buildTarget, subtarget, options.options, out updateExistingBuild))
                                        throw new BuildMethodException();

                                    newLocation = EditorUserBuildSettings.GetBuildLocation(buildTarget);
                                    if (!BuildLocationIsValid(newLocation))
                                        throw new BuildMethodException("Build location for buildTarget " + buildTarget + " is not valid.");

View on GitHub (pinned to 225b0fbdb5)

Solutions

  1. Pre-set the build location via EditorUserBuildSettings.SetBuildLocation(buildTarget, path) before building.
  2. Allow the location picker (askForBuildLocation) so the user can choose a path.
  3. Pass an explicit locationPathName in BuildPlayerOptions instead of relying on stored settings.

Example fix

// before
EditorUserBuildSettings.SetBuildLocation(BuildTarget.StandaloneWindows64, "");
// ... build with askForBuildLocation=false -> throws

// after
EditorUserBuildSettings.SetBuildLocation(BuildTarget.StandaloneWindows64, "/abs/path/Build");
// then build
Defensive patterns

Strategy: validation

Validate before calling

var loc = EditorUserBuildSettings.GetBuildLocation(buildTarget);
if (string.IsNullOrEmpty(loc))
    EditorUserBuildSettings.SetBuildLocation(buildTarget, Path.GetFullPath(defaultPath));

Prevention

When it happens

Trigger: askForBuildLocation is false (or the picker was bypassed) and GetBuildLocation(buildTarget) returns ""; no prior build location was ever recorded for the target.

Common situations: Headless/CI build that skips the location picker without pre-setting a build location; first build for a target where no location has been chosen before; a build script cleared the stored location.

Related errors


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