{"record":{"id":"9719cfbdde5589f1","repo":"Unity-Technologies/UnityCsReference","slug":"input-0-is-not-a-plain-gameobject-it-is-alrea","errorCode":null,"errorMessage":"Input '{0}' is not a plain GameObject, it is already a Prefab instance. Use ReplacePrefabAssetOfPrefabInstance() instead.","messagePattern":"Input '(.+?)' is not a plain GameObject, it is already a Prefab instance\\. Use ReplacePrefabAssetOfPrefabInstance\\(\\) instead\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"Editor/Mono/Prefabs/PrefabUtility.cs","lineNumber":2352,"sourceCode":"            if (!success)\n            {\n                Debug.LogError(string.Format(\"Replace Prefab Instance failed for instance '{0}' using asset '{1}' at '{2}'\", prefabInstanceRoot.name, prefabAssetRoot.name, AssetDatabase.GetAssetPath(prefabAssetRoot)), prefabInstanceRoot);\n            }\n\n            if (mode == InteractionMode.UserAction)\n                Undo.FlushTrackedObjects();\n        }\n\n        internal static void ThrowIfInvalidArgumentsForConvertToPrefabInstance(GameObject plainGameObject, GameObject prefabAssetRoot, bool checkValidAsset, InteractionMode mode)\n        {\n            if (plainGameObject == null)\n                throw new ArgumentNullException(nameof(plainGameObject));\n\n            if (prefabAssetRoot == null)\n                throw new ArgumentNullException(nameof(prefabAssetRoot));\n\n            if (IsPartOfNonAssetPrefabInstance(plainGameObject))\n                throw new InvalidOperationException(string.Format(\"Input '{0}' is not a plain GameObject, it is already a Prefab instance. Use ReplacePrefabAssetOfPrefabInstance() instead.\", plainGameObject.name));\n\n            if (EditorUtility.IsPersistent(plainGameObject))\n                throw new ArgumentException(\"Input is from a Prefab asset, this is not supported. Input GameObject: \" + plainGameObject.name, nameof(plainGameObject));\n\n            if (checkValidAsset)\n                ThrowIfInvalidAssetForReplacePrefabInstance(prefabAssetRoot, mode);\n\n            if (plainGameObject.transform.GetType() != prefabAssetRoot.transform.GetType())\n                throw new InvalidOperationException(string.Format(\"Cannot convert the GameObject '{0}' with root transform of type {1} with a Prefab asset with root transform of type {2}. Transform types must match.\", plainGameObject.name, plainGameObject.transform.GetType().Name, prefabAssetRoot.transform.GetType().Name));\n\n            // Prefab Mode and EditPrefabContents scope handling\n            if (PrefabStageUtility.IsGameObjectThePrefabRootInAnyPrefabStage(plainGameObject) || (EditorSceneManager.IsPreviewSceneObject(plainGameObject) && plainGameObject.transform.parent == null))\n                throw new InvalidOperationException(\"Replacing the root GameObject in a Prefab with a Prefab instance is not supported since it will break all overrides for existing instances of this Prefab, including their positions and rotations.\" + plainGameObject.name);\n\n            if (plainGameObject.hideFlags.HasFlag(HideFlags.DontSaveInEditor) || plainGameObject.transform.hideFlags.HasFlag(HideFlags.DontSaveInEditor))\n                throw new ArgumentException(\"Input GameObject is using the HideFlags.DontSaveInEditor flag which is not supported when converting to Prefab instance: GameObject: \" + plainGameObject.name, nameof(plainGameObject));\n\n            if (mode == InteractionMode.UserAction)","sourceCodeStart":2334,"sourceCodeEnd":2370,"githubUrl":"https://github.com/Unity-Technologies/UnityCsReference/blob/225b0fbdb57cc17d094e8056b71f8314aba56f73/Editor/Mono/Prefabs/PrefabUtility.cs#L2334-L2370","documentation":"Thrown by ThrowIfInvalidArgumentsForConvertToPrefabInstance when IsPartOfNonAssetPrefabInstance(plainGameObject) returns true. ConvertToPrefabInstance expects a plain scene GameObject — one that is NOT already a Prefab instance. If the object is already a Prefab instance, the correct API is ReplacePrefabAssetOfPrefabInstance(), which swaps the underlying asset.","triggerScenarios":"Calling ConvertToPrefabInstance on a GameObject that was already instantiated from a Prefab (i.e. it is a Prefab instance). E.g. a scene object created via Instantiate(prefabAsset) passed to ConvertToPrefabInstance.","commonSituations":"Generic 'apply Prefab' code that doesn't distinguish plain GameObjects from existing instances. Re-running a conversion script on objects that were already converted in a previous pass.","solutions":["If the object is already a Prefab instance, call PrefabUtility.ReplacePrefabAssetOfPrefabInstance() instead.","Guard with: if (PrefabUtility.IsPartOfNonAssetPrefabInstance(obj)) call Replace; else call Convert.","Unpack the Prefab instance (UnpackPrefabInstance) first if you truly need to re-convert."],"exampleFix":"// before\nPrefabUtility.ConvertToPrefabInstance(myGo, prefabAsset, settings, mode);\n// myGo is already a Prefab instance\n\n// after\nif (PrefabUtility.IsPartOfNonAssetPrefabInstance(myGo))\n    PrefabUtility.ReplacePrefabAssetOfPrefabInstance(myGo, prefabAsset, mode);\nelse\n    PrefabUtility.ConvertToPrefabInstance(myGo, prefabAsset, settings, mode);","handlingStrategy":"validation","validationCode":"if (PrefabUtility.IsPartOfNonAssetPrefabInstance(plainGameObject))\n{\n    PrefabUtility.ReplacePrefabAssetOfPrefabInstance(plainGameObject, prefabAssetRoot, mode);\n    return;\n}\nPrefabUtility.ConvertToPrefabInstance(plainGameObject, prefabAssetRoot, settings, mode);","typeGuard":"static bool IsPlainSceneGameObject(GameObject obj)\n{\n    return obj != null\n        && !PrefabUtility.IsPartOfNonAssetPrefabInstance(obj)\n        && !EditorUtility.IsPersistent(obj);\n}","tryCatchPattern":null,"preventionTips":["Branch on IsPartOfNonAssetPrefabInstance to pick Convert vs Replace.","Track which objects have already been converted to avoid double-processing."],"tags":["prefab","argument-validation","gameobject","unity-editor"],"backgroundTag":null,"analyzedSha":"225b0fbdb57cc17d094e8056b71f8314aba56f73","analyzedAt":"2026-08-13T19:07:19.849Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}