{"record":{"id":"b6c45eda7a5b3b25","repo":"Unity-Technologies/UnityCsReference","slug":"input-gameobject-is-using-the-hideflags-dontsavein","errorCode":null,"errorMessage":"Input GameObject is using the HideFlags.DontSaveInEditor flag which is not supported when converting to Prefab instance: GameObject: ","messagePattern":"Input GameObject is using the HideFlags\\.DontSaveInEditor flag which is not supported when converting to Prefab instance: GameObject: ","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"Editor/Mono/Prefabs/PrefabUtility.cs","lineNumber":2368,"sourceCode":"\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);\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        }","sourceCodeStart":2350,"sourceCodeEnd":2386,"githubUrl":"https://github.com/Unity-Technologies/UnityCsReference/blob/225b0fbdb57cc17d094e8056b71f8314aba56f73/Editor/Mono/Prefabs/PrefabUtility.cs#L2350-L2386","documentation":"Thrown by ThrowIfInvalidArgumentsForConvertToPrefabInstance when plainGameObject.hideFlags or its transform's hideFlags includes HideFlags.DontSaveInEditor. Objects flagged DontSaveInEditor are intentionally excluded from serialization, so converting them to a Prefab instance would produce inconsistent state. Unity rejects them before performing the conversion.","triggerScenarios":"Converting an editor-only transient GameObject (created with HideFlags.DontSaveInEditor) that was never meant to be saved. Custom preview/gizmo objects that are accidentally targeted by a conversion script.","commonSituations":"Editor extensions that create helper objects with DontSaveInEditor. Objects left behind by deleted tools that still carry the flag.","solutions":["Clear the DontSaveInEditor flag before converting: plainGameObject.hideFlags = HideFlags.None.","Operate on a normal serialized scene GameObject instead.","Guard: if (obj.hideFlags.HasFlag(HideFlags.DontSaveInEditor)) return;"],"exampleFix":"// before\nPrefabUtility.ConvertToPrefabInstance(myGo, prefabAsset, settings, mode);\n// myGo has HideFlags.DontSaveInEditor\n\n// after\nmyGo.hideFlags = HideFlags.None;\nmyGo.transform.hideFlags = HideFlags.None;\nPrefabUtility.ConvertToPrefabInstance(myGo, prefabAsset, settings, mode);","handlingStrategy":"validation","validationCode":"if (plainGameObject.hideFlags.HasFlag(HideFlags.DontSaveInEditor)\n    || plainGameObject.transform.hideFlags.HasFlag(HideFlags.DontSaveInEditor))\n{\n    plainGameObject.hideFlags = HideFlags.None;\n    plainGameObject.transform.hideFlags = HideFlags.None;\n}\nPrefabUtility.ConvertToPrefabInstance(plainGameObject, prefabAssetRoot, settings, mode);","typeGuard":"static bool HasNoDontSaveFlag(GameObject obj)\n{\n    return obj != null\n        && !obj.hideFlags.HasFlag(HideFlags.DontSaveInEditor)\n        && !obj.transform.hideFlags.HasFlag(HideFlags.DontSaveInEditor);\n}","tryCatchPattern":null,"preventionTips":["Don't set DontSaveInEditor on objects targeted by Prefab conversion.","Audit transient editor objects for stray hide flags before batch operations."],"tags":["prefab","hideflags","dont-save-in-editor","argument-validation","unity-editor"],"backgroundTag":null,"analyzedSha":"225b0fbdb57cc17d094e8056b71f8314aba56f73","analyzedAt":"2026-08-13T19:07:19.849Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}