{"record":{"id":"4b24b664493920e6","repo":"Unity-Technologies/UnityCsReference","slug":"cannot-convert-the-gameobject-when-it-has-a-missin","errorCode":null,"errorMessage":"Cannot convert the GameObject when it has a missing script. GameObject '{gameObjectsWithInvalidScript[0].name}' has a missing script. This is not supported by the Undo system. Use InteractionMode.AutomatedAction instead.","messagePattern":"Cannot convert the GameObject when it has a missing script\\. GameObject '(.+?)' has a missing script\\. This is not supported by the Undo system\\. Use InteractionMode\\.AutomatedAction instead\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"Editor/Mono/Prefabs/PrefabUtility.cs","lineNumber":2375,"sourceCode":"            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);\n                if (gameObjectsWithInvalidScript.Count > 0)\n                    throw new InvalidOperationException(string.Format($\"Cannot convert the GameObject when it has a missing script. GameObject '{gameObjectsWithInvalidScript[0].name}' has a missing script. This is not supported by the Undo system. Use InteractionMode.AutomatedAction instead.\"));\n            }\n        }\n\n        public static void ConvertToPrefabInstance(GameObject plainGameObject, GameObject prefabAssetRoot, ConvertToPrefabInstanceSettings settings, InteractionMode mode)\n        {\n            ThrowIfInvalidArgumentsForConvertToPrefabInstance(plainGameObject, prefabAssetRoot, true, mode);\n\n            ConvertToPrefabInstance_NoInputValidation(plainGameObject, prefabAssetRoot, settings, mode);\n\n            EditorUtility.ForceRebuildInspectors();\n        }\n\n        public static void ConvertToPrefabInstances(GameObject[] plainGameObjects, GameObject prefabAssetRoot, ConvertToPrefabInstanceSettings settings, InteractionMode mode)\n        {\n            if (plainGameObjects == null)\n                throw new ArgumentNullException(nameof(plainGameObjects));\n\n            if (plainGameObjects.Length == 0)","sourceCodeStart":2357,"sourceCodeEnd":2393,"githubUrl":"https://github.com/Unity-Technologies/UnityCsReference/blob/225b0fbdb57cc17d094e8056b71f8314aba56f73/Editor/Mono/Prefabs/PrefabUtility.cs#L2357-L2393","documentation":"Thrown by ThrowIfInvalidArgumentsForConvertToPrefabInstance when mode == InteractionMode.UserAction and FindGameObjectsWithInvalidComponent(plainGameObject) finds at least one GameObject with a missing script. Unity's Undo system cannot record changes involving missing scripts, so a user-action conversion is blocked. The message names the offending GameObject and advises using InteractionMode.AutomatedAction to bypass Undo.","triggerScenarios":"A plain GameObject (or one of its children) has a 'Missing (Mono Script)' component. Calling ConvertToPrefabInstance with InteractionMode.UserAction on such an object.","commonSituations":"After deleting a script used by scene objects without removing the components. Project upgrade where an assembly is missing. Importing scene data from a collaborator missing scripts.","solutions":["Remove the missing script components before converting (Inspector right-click → Remove Component, or GameObjectUtility.RemoveMonoScripts).","Pass InteractionMode.AutomatedAction instead of UserAction if Undo support is not needed.","Fix compilation errors / restore the missing MonoScript so the component resolves."],"exampleFix":"// before\nPrefabUtility.ConvertToPrefabInstance(plainGo, prefabAsset, settings, InteractionMode.UserAction);\n// Throws: plainGo (or a child) has a missing script\n\n// after — use AutomatedAction to bypass the Undo limitation\nPrefabUtility.ConvertToPrefabInstance(plainGo, prefabAsset, settings, InteractionMode.AutomatedAction);","handlingStrategy":"validation","validationCode":"if (mode == InteractionMode.UserAction)\n{\n    var invalid = PrefabUtility.FindGameObjectsWithInvalidComponent(plainGameObject);\n    if (invalid.Count > 0)\n        mode = InteractionMode.AutomatedAction;\n}\nPrefabUtility.ConvertToPrefabInstance(plainGameObject, prefabAssetRoot, settings, mode);","typeGuard":"static bool HasNoMissingScripts(GameObject root)\n{\n    return PrefabUtility.FindGameObjectsWithInvalidComponent(root).Count == 0;\n}","tryCatchPattern":null,"preventionTips":["Remove missing script components before running conversions.","Use InteractionMode.AutomatedAction in pipelines where Undo is not needed."],"tags":["prefab","missing-script","undo","interaction-mode","unity-editor"],"backgroundTag":null,"analyzedSha":"225b0fbdb57cc17d094e8056b71f8314aba56f73","analyzedAt":"2026-08-13T19:07:19.849Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}