Unity-Technologies/UnityCsReference · error · ArgumentException
Creating a variant of an object into the source file of the
Error message
Creating a variant of an object into the source file of the input object is not allowed
What it means
Thrown by CreateVariant when the destination `path` resolves to the same file as the source prefab asset (case-insensitive compare via Paths.AreEqual). Creating a variant of a prefab into its own source file would produce a self-referential/corrupt asset, so Unity blocks it. The check runs only after path is confirmed non-null.
Source
Thrown at Editor/Mono/Prefabs/PrefabUtility.bindings.cs:241
extern public static GameObject FindPrefabRoot([NotNull] GameObject source);
internal static GameObject CreateVariant(GameObject assetRoot, string path)
{
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)]View on GitHub (pinned to 225b0fbdb5)
Solutions
- Choose a distinct output filename, e.g. append "Variant": AssetDatabase.GenerateUniqueAssetPath("Assets/Prefabs/" + root.name + "Variant.prefab").
- Verify the resolved path differs from AssetDatabase.GetAssetPath(assetRoot) before calling.
- Prompt the user to pick a different folder/file if they reused the source name.
Example fix
// before
string srcPath = AssetDatabase.GetAssetPath(root);
var v = PrefabUtility.CreateVariant(root, srcPath); // throws
// after
string dir = System.IO.Path.GetDirectoryName(srcPath);
string newPath = AssetDatabase.GenerateUniqueAssetPath(
dir + "/" + root.name + "Variant.prefab");
var v = PrefabUtility.CreateVariant(root, newPath); Defensive patterns
Strategy: validation
Validate before calling
string srcPath = AssetDatabase.GetAssetPath(assetRoot);
if (PathsAreEqual(path, srcPath))
path = AssetDatabase.GenerateUniqueAssetPath(
System.IO.Path.GetDirectoryName(srcPath).Replace('\\','/') + "/" + assetRoot.name + "Variant.prefab"); Prevention
- Always derive a new filename (append 'Variant' or a counter) from the source path.
- Compare against AssetDatabase.GetAssetPath(assetRoot) case-insensitively before calling.
- Use GenerateUniqueAssetPath so duplicates never collide with the source.
When it happens
Trigger: Calling CreateVariant with a path equal to `AssetDatabase.GetAssetPath(assetRoot)`, or a path differing only by case. Reusing the original prefab's path verbatim, or generating the variant path from the source asset path without changing the filename.
Common situations: Right-click 'Create Variant' workflows where the user picked the same filename, or scripts that derive the output path from the input asset path without appending a suffix. Cross-platform case-insensitive filesystems making two apparently different paths collide.
Related errors
- Given path is not valid: '{path}'
- 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/78953512605fddcf.
Report an issue: GitHub.