{"record":{"id":"66a89cb29e1124c3","repo":"Unity-Technologies/UnityCsReference","slug":"input-is-from-a-prefab-asset-this-is-not-supporte","errorCode":null,"errorMessage":"Input is from a Prefab asset, this is not supported. Input GameObject: ","messagePattern":"Input is from a Prefab asset, this is not supported\\. Input GameObject: ","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"Editor/Mono/Prefabs/PrefabUtility.cs","lineNumber":2355,"sourceCode":"            }\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)\n            {\n                // Recording undo does not handle missing scripts\n                var gameObjectsWithInvalidScript = FindGameObjectsWithInvalidComponent(plainGameObject);","sourceCodeStart":2337,"sourceCodeEnd":2373,"githubUrl":"https://github.com/Unity-Technologies/UnityCsReference/blob/225b0fbdb57cc17d094e8056b71f8314aba56f73/Editor/Mono/Prefabs/PrefabUtility.cs#L2337-L2373","documentation":"Thrown by ThrowIfInvalidArgumentsForConvertToPrefabInstance when EditorUtility.IsPersistent(plainGameObject) is true. The input must be a plain scene GameObject, not an asset stored on disk. Passing a Prefab asset root (loaded from the Asset Database) is rejected because ConvertToPrefabInstance operates on live scene objects.","triggerScenarios":"Loading a GameObject via AssetDatabase.LoadAssetAtPath or Resources.Load and passing it to ConvertToPrefabInstance. Using AssetDatabase.FindAssets to enumerate objects and calling convert on the asset references.","commonSituations":"Confusing a Prefab asset (on disk) with a plain GameObject (in scene). Code that processes project-level assets instead of scene instances.","solutions":["Operate on a scene-level GameObject, not an asset reference.","If the asset is a plain .prefab you want to edit, use PrefabUtility.LoadPrefabContents / SaveAsPrefabAsset instead.","Guard: if (EditorUtility.IsPersistent(obj)) return;"],"exampleFix":"// before\nvar assetGo = AssetDatabase.LoadAssetAtPath<GameObject>(\"Assets/Plain.prefab\");\nPrefabUtility.ConvertToPrefabInstance(assetGo, prefabAsset, settings, mode);\n\n// after — load contents, modify, save\nvar contents = PrefabUtility.LoadPrefabContents(\"Assets/Plain.prefab\");\n// ... operate on contents in the preview scene ...\nPrefabUtility.SaveAsPrefabAsset(contents, \"Assets/Plain.prefab\");\nPrefabUtility.UnloadPrefabContents(contents);","handlingStrategy":"validation","validationCode":"if (EditorUtility.IsPersistent(plainGameObject))\n{\n    Debug.LogError(\"Input is a persistent asset, not a scene GameObject. Use LoadPrefabContents/SaveAsPrefabAsset instead.\");\n    return;\n}\nPrefabUtility.ConvertToPrefabInstance(plainGameObject, prefabAssetRoot, settings, mode);","typeGuard":"static bool IsSceneGameObject(GameObject obj)\n{\n    return obj != null && !EditorUtility.IsPersistent(obj);\n}","tryCatchPattern":null,"preventionTips":["Use EditorUtility.IsPersistent to distinguish assets from scene objects.","For asset-level edits, prefer LoadPrefabContents / SaveAsPrefabAsset."],"tags":["prefab","persistent-asset","argument-validation","unity-editor"],"backgroundTag":null,"analyzedSha":"225b0fbdb57cc17d094e8056b71f8314aba56f73","analyzedAt":"2026-08-13T19:07:19.849Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}