Unity-Technologies/UnityCsReference · error · ArgumentException
Path {scenePath} is not a scene path. Must end with .unity e
Error message
Path {scenePath} is not a scene path. Must end with .unity extension. What it means
Thrown by CreateLoadableSceneId when scenePath is non-empty but does not end with the '.unity' extension (case-insensitive). The factory only accepts genuine scene asset paths.
Source
Thrown at Editor/Mono/Loadable/LoadableSceneIdEditorUtility.cs:70
}
/// <summary>
/// Create a LoadableSceneId object based on a scene's path.
/// </summary>
/// <param name="scenePath">The scene's path within the project. Must end with .unity extension.</param>
/// <returns>A LoadableSceneId handle populated to reference the provided scene.</returns>
/// <exception cref="System.ArgumentNullException">
/// Thrown if scenePath is null or empty.
/// </exception>
/// <exception cref="System.ArgumentException">
/// Thrown if the path doesn't end with .unity extension or if the scene asset cannot be found at the specified path.
/// </exception>
public static LoadableSceneId CreateLoadableSceneId(string scenePath)
{
if (string.IsNullOrEmpty(scenePath))
throw new ArgumentNullException(nameof(scenePath), "Scene path cannot be null or empty.");
if (!scenePath.EndsWith(".unity", StringComparison.CurrentCultureIgnoreCase))
throw new ArgumentException($"Path {scenePath} is not a scene path. Must end with .unity extension.");
var guid = new GUID(AssetDatabase.AssetPathToGUID(scenePath));
if (guid.Empty())
throw new ArgumentException($"Couldn't locate scene asset at path {scenePath}");
return CreateLoadableSceneId(guid);
}
}
}
View on GitHub (pinned to 225b0fbdb5)
Solutions
- Ensure the path passed is the AssetDatabase path of an actual SceneAsset.
- Constrain the picker/construction to SceneAsset so the extension is always correct.
- Normalize/append '.unity' only if the input is genuinely a scene path that lost its extension.
Example fix
// before
var id = LoadableSceneIdEditorUtility.CreateLoadableSceneId(assetPath);
// after
if (!assetPath.EndsWith(".unity", StringComparison.OrdinalIgnoreCase))
throw new ArgumentException($"{assetPath} is not a scene.");
var id = LoadableSceneIdEditorUtility.CreateLoadableSceneId(assetPath); Defensive patterns
Strategy: validation
Validate before calling
if (!scenePath.EndsWith(".unity", System.StringComparison.OrdinalIgnoreCase)) throw new ArgumentException("Not a scene path."); Type guard
static bool IsScenePath(string p) => p != null && p.EndsWith(".unity", System.StringComparison.OrdinalIgnoreCase); Try / catch
try { CreateLoadableSceneId(scenePath); }
catch (ArgumentException ex) when (ex.Message.Contains(".unity")) { Debug.LogError(ex.Message); } Prevention
- Constrain pickers to SceneAsset
- Derive paths from SceneAsset via AssetDatabase.GetAssetPath
- Normalize extensions explicitly
When it happens
Trigger: Passing a path to a non-scene asset (.prefab, .unity scene excluded on purpose, .asset), a directory path, or a path with the wrong extension. Also a typo in the extension.
Common situations: A UI that lets users pick any Object instead of a SceneAsset. Code that derives a scene path by string manipulation and drops or misspells the extension. Mixing prefab and scene concepts.
Related errors
- Scene path cannot be null or empty.
- Preview scene could not be created
- Couldn't locate scene asset at path {scenePath}
- No material targets provided
- src
AI-assisted analysis of Unity-Technologies/UnityCsReference@225b0fbdb5 (2026-08-13).
Data as JSON: /api/errors/8b7881f0ed9c4c80.
Report an issue: GitHub.