Unity-Technologies/UnityCsReference · error · ArgumentException
Given path is not valid: '{path}'
Error message
Given path is not valid: '{path}' What it means
Thrown by CreateVariant when `Paths.IsValidAssetPath(path, ".prefab")` returns false. This validates that the path lives under the project's Assets folder, is a valid asset path string, and ends with the required '.prefab' extension. It fires only after the null and source-collision checks pass.
Source
Thrown at Editor/Mono/Prefabs/PrefabUtility.bindings.cs:244
{
if (assetRoot == null)
throw new ArgumentNullException("The inputObject is null");
if (!IsPartOfPrefabAsset(assetRoot))
throw new ArgumentException("Given input object is not a prefab asset");
if (assetRoot.transform.root.gameObject != assetRoot)
throw new ArgumentException("Object to create variant from has to be a Prefab root");
if (path == null)
throw new ArgumentNullException("The path is null");
var assetRootObjectPath = AssetDatabase.GetAssetPath(assetRoot);
if (Paths.AreEqual(path, assetRootObjectPath, true))
throw new ArgumentException("Creating a variant of an object into the source file of the input object is not allowed");
if (!Paths.IsValidAssetPath(path, ".prefab"))
throw new ArgumentException("Given path is not valid: '" + path + "'");
return CreateVariant_Internal(assetRoot, path);
}
[NativeMethod("CreateVariant", IsFreeFunction = true)]
extern private static GameObject CreateVariant_Internal([NotNull] GameObject original, string path);
[StaticAccessor("PrefabUtilityBindings", StaticAccessorType.DoubleColon)]
[NativeMethod(ThrowsException = true)]
extern private static GameObject SavePrefab_Internal([NotNull] GameObject root, string path, bool connectToInstance, out bool success);
[StaticAccessor("PrefabUtilityBindings", StaticAccessorType.DoubleColon)]
extern private static GameObject ApplyPrefabInstance_Internal([NotNull] GameObject root);
[StaticAccessor("PrefabUtilityBindings", StaticAccessorType.DoubleColon)]
[NativeMethod(ThrowsException = true)]
extern private static GameObject SaveAsPrefabAsset_Internal([NotNull] GameObject root, string path, out bool success);
View on GitHub (pinned to 225b0fbdb5)
Solutions
- Use a Unity-relative path rooted in Assets with a .prefab extension: "Assets/Prefabs/Name.prefab".
- Ensure the parent directory exists under Assets (use AssetDatabase to create folders if needed).
- Build the path with AssetDatabase.GenerateUniqueAssetPath to normalize it.
- Strip drive letters and backslashes; convert to forward slashes and an Assets/ prefix.
Example fix
// before var v = PrefabUtility.CreateVariant(root, @"C:\Proj\Variant.prefab"); // invalid // after string rel = "Assets/Prefabs/" + root.name + "Variant.prefab"; rel = AssetDatabase.GenerateUniqueAssetPath(rel); var v = PrefabUtility.CreateVariant(root, rel);
Defensive patterns
Strategy: validation
Validate before calling
if (!path.StartsWith("Assets/") || !path.EndsWith(".prefab", System.StringComparison.OrdinalIgnoreCase))
path = AssetDatabase.GenerateUniqueAssetPath("Assets/Prefabs/" + assetRoot.name + "Variant.prefab"); Prevention
- Never pass absolute OS paths; always use Unity-relative 'Assets/...' paths.
- Always include the '.prefab' extension explicitly.
- Prefer AssetDatabase.GenerateUniqueAssetPath to normalize and validate in one step.
When it happens
Trigger: Passing an absolute filesystem path (e.g. "C:/.../Foo.prefab"), a path outside the Assets folder, a path with no '.prefab' extension, a path with a different extension, or a path containing illegal characters/empty segments.
Common situations: Using System.IO absolute paths instead of Unity-relative 'Assets/...' paths. Forgetting the '.prefab' extension. Typing a folder that does not exist under Assets. Copying a path from Explorer that includes a drive letter.
Related errors
- Creating a variant of an object into the source file of the
- ApplyPrefabAddedGameObjects requires that GameObjects share
- The path is null
- Prefab Asset path is null or empty
- The Prefab you want to instantiate is null.
AI-assisted analysis of Unity-Technologies/UnityCsReference@225b0fbdb5 (2026-08-13).
Data as JSON: /api/errors/23450a1d1014a894.
Report an issue: GitHub.