{"record":{"id":"3dbfa9e8452cabe6","repo":"Unity-Technologies/UnityCsReference","slug":"given-input-object-is-not-a-prefab-asset","errorCode":null,"errorMessage":"Given input object is not a prefab asset","messagePattern":"Given input object is not a prefab asset","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"Editor/Mono/Prefabs/PrefabUtility.bindings.cs","lineNumber":231,"sourceCode":"        [FreeFunction]\n        extern public static bool RevertPrefabInstance([NotNull] GameObject go);\n\n        // Resets the properties of all objects in the prefab, including child game objects and components that were added to the prefab instance\n        [NativeMethod(\"RevertPrefabInstance\", IsFreeFunction = true)]\n        extern private static bool RevertPrefabInstance_Internal([NotNull] GameObject go);\n\n        // Helper function to find the prefab root of an object\n        [FreeFunction]\n        [Obsolete(\"Use GetOutermostPrefabInstanceRoot if source is a Prefab instance or source.transform.root.gameObject if source is a Prefab Asset object.\")]\n        extern public static GameObject FindPrefabRoot([NotNull] GameObject source);\n\n        internal static GameObject CreateVariant(GameObject assetRoot, string path)\n        {\n            if (assetRoot == null)\n                throw new ArgumentNullException(\"The inputObject is null\");\n\n            if (!IsPartOfPrefabAsset(assetRoot))\n                throw new ArgumentException(\"Given input object is not a prefab asset\");\n\n            if (assetRoot.transform.root.gameObject != assetRoot)\n                throw new ArgumentException(\"Object to create variant from has to be a Prefab root\");\n\n            if (path == null)\n                throw new ArgumentNullException(\"The path is null\");\n\n            var assetRootObjectPath = AssetDatabase.GetAssetPath(assetRoot);\n            if (Paths.AreEqual(path, assetRootObjectPath, true))\n                throw new ArgumentException(\"Creating a variant of an object into the source file of the input object is not allowed\");\n\n            if (!Paths.IsValidAssetPath(path, \".prefab\"))\n                throw new ArgumentException(\"Given path is not valid: '\" + path + \"'\");\n\n            return CreateVariant_Internal(assetRoot, path);\n        }\n\n        [NativeMethod(\"CreateVariant\", IsFreeFunction = true)]","sourceCodeStart":213,"sourceCodeEnd":249,"githubUrl":"https://github.com/Unity-Technologies/UnityCsReference/blob/225b0fbdb57cc17d094e8056b71f8314aba56f73/Editor/Mono/Prefabs/PrefabUtility.bindings.cs#L213-L249","documentation":"PrefabUtility.CreateVariant checks that the provided assetRoot is part of a prefab asset (PrefabUtility.IsPartOfPrefabAsset returns true) and throws ArgumentException('Given input object is not a prefab asset') otherwise. This ensures the variant source is an actual prefab saved in the project, not a scene object or a prefab instance in a scene. Variants can only derive from prefab assets.","triggerScenarios":"Calling CreateVariant with a scene-level GameObject, a prefab instance (not the asset), or any object that is not part of a prefab asset file. Passing a runtime-instantiated prefab instead of the asset reference.","commonSituations":"Editor tools that operate on Selection.activeGameObject (which could be a scene instance, not the asset). Code that confuses prefab instances with prefab assets. Automation that receives objects from scene traversal rather than AssetDatabase lookups.","solutions":["Call PrefabUtility.IsPartOfPrefabAsset(go) before invoking CreateVariant","If starting from a prefab instance, get the corresponding asset via PrefabUtility.GetCorrespondingObjectFromSource or PrefabUtility.GetPrefabAssetPathOfNearestInstanceRoot","Use AssetDatabase.LoadAssetAtPath to load the prefab asset explicitly before creating a variant"],"exampleFix":"// before\nvar variant = PrefabUtility.CreateVariant(sceneInstance, \"Assets/Variant.prefab\");\n\n// after\nGameObject assetRoot = PrefabUtility.IsPartOfPrefabAsset(go) ? go : AssetDatabase.LoadAssetAtPath<GameObject>(PrefabUtility.GetPrefabAssetPathOfNearestInstanceRoot(go));\nif (assetRoot != null && PrefabUtility.IsPartOfPrefabAsset(assetRoot))\n    var variant = PrefabUtility.CreateVariant(assetRoot, \"Assets/Variant.prefab\");","handlingStrategy":"validation","validationCode":"if (!PrefabUtility.IsPartOfPrefabAsset(assetRoot))\n{\n    Debug.LogError(\"CreateVariant requires a prefab asset, not a scene object or instance.\");\n    return;\n}\n// Safe to call CreateVariant(assetRoot, path)","typeGuard":"static bool IsPrefabAsset(GameObject go) => go != null && PrefabUtility.IsPartOfPrefabAsset(go);","tryCatchPattern":"try { var variant = PrefabUtility.CreateVariant(assetRoot, path); }\ncatch (ArgumentException ex) when (ex.Message == \"Given input object is not a prefab asset\")\n{ Debug.LogError($\"{assetRoot?.name} is not a prefab asset. Load via AssetDatabase.LoadAssetAtPath.\"); }","preventionTips":["Call PrefabUtility.IsPartOfPrefabAsset before CreateVariant","If starting from a scene instance, resolve the source asset via GetCorrespondingObjectFromSource","Use AssetDatabase.LoadAssetAtPath<GameObject> to load the prefab asset explicitly"],"tags":["unity","editor-scripting","prefab","validation","prefab-asset","prefab-variant","argumentexception"],"backgroundTag":null,"analyzedSha":"225b0fbdb57cc17d094e8056b71f8314aba56f73","analyzedAt":"2026-08-13T19:07:19.849Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}