Unity-Technologies/UnityCsReference · error · ArgumentException
Scene path "{0}" contains invalid directory separators.
Error message
Scene path "{0}" contains invalid directory separators. What it means
Thrown by ValidateScenePaths during BuildPlayer when a scene path contains triple forward slashes ('///') after backslash-to-forward-slash normalization. The build pipeline normalizes path separators but rejects paths that still contain '///' since they represent an ambiguous directory structure that cannot be resolved.
Source
Thrown at Editor/Mono/BuildPipeline/BuildPipeline.bindings.cs:213
///<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("//", "/");
}
if ((buildPlayerOptions.options & BuildOptions.Development) == 0)
{View on GitHub (pinned to 225b0fbdb5)
Solutions
- Sanitize every scene path before passing it to BuildPlayer: path.Replace('\\','/'); then collapse runs of slashes with a loop or regex like Regex.Replace(path, @"/{2,}", "/").
- Inspect the offending scene path printed in the error message and fix the source that generated it.
- Use Unity's AssetDatabase to load scene GUIDs and resolve canonical paths instead of hand-building path strings.
Example fix
// before
var options = new BuildPlayerOptions
{
scenes = new[] { "Assets///Scenes/Game.unity" },
locationPathName = "Build/game",
target = BuildTarget.StandaloneWindows64
};
BuildPipeline.BuildPlayer(options);
// after
string NormalizeScenePath(string p) =>
System.Text.RegularExpressions.Regex.Replace(p.Replace('\\', '/'), @"/{2,}", "/");
var options = new BuildPlayerOptions
{
scenes = new[] { NormalizeScenePath("Assets///Scenes/Game.unity") },
locationPathName = "Build/game",
target = BuildTarget.StandaloneWindows64
};
BuildPipeline.BuildPlayer(options); Defensive patterns
Strategy: validation
Validate before calling
static string NormalizeScenePath(string p)
{
string normalized = p.Replace('\\', '/');
normalized = System.Text.RegularExpressions.Regex.Replace(normalized, @"/{2,}", "/");
if (normalized.Contains("///"))
throw new ArgumentException($"Scene path still invalid after normalization: {p}");
return normalized;
}
// Before BuildPlayer:
options.scenes = options.scenes
.Select(NormalizeScenePath)
.ToArray(); Prevention
- Always normalize scene paths with Replace('\\','/') and collapse repeated slashes before passing them to BuildPlayer.
- Prefer loading scene paths via EditorBuildSettings.scenes or AssetDatabase to get canonical paths instead of hand-building strings.
- Add a pre-build validation step in your build script that checks every scene path for '///' and fails fast with a clear message.
When it happens
Trigger: Calling BuildPipeline.BuildPlayer with a BuildPlayerOptions.scenes array entry like 'Assets///Scenes/MyScene.unity', or a path where backslash normalization collapses into '///' (e.g., 'Assets\\//Scenes/MyScene.unity'). The validation runs on each scene string after Replace('\\','/') so any source path producing three consecutive slashes triggers it.
Common situations: Paths assembled via string concatenation with extra separators, paths sourced from external XML/JSON config files with inconsistent delimiters, cross-platform path-handling bugs where code prepends or appends '/' unconditionally, and editor scripts that build paths from user input without sanitization.
Related errors
- Invalid build path: '{buildPlayerOptions.locationPathName}'.
- The build target does not support build appending.
- BuildContentDirectoryParameters.outputPath cannot be empty
- The output path "{buildParameters.outputPath}" doesn't exist
- The build cannot be appended.
AI-assisted analysis of Unity-Technologies/UnityCsReference@225b0fbdb5 (2026-08-13).
Data as JSON: /api/errors/b9655c383621f828.
Report an issue: GitHub.