Unity-Technologies/UnityCsReference · error · ArgumentException
Input GameObject is using the HideFlags.DontSaveInEditor fla
Error message
Input GameObject is using the HideFlags.DontSaveInEditor flag which is not supported when converting to Prefab instance: GameObject:
What it means
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.
Source
Thrown at Editor/Mono/Prefabs/PrefabUtility.cs:2368
if (IsPartOfNonAssetPrefabInstance(plainGameObject))
throw new InvalidOperationException(string.Format("Input '{0}' is not a plain GameObject, it is already a Prefab instance. Use ReplacePrefabAssetOfPrefabInstance() instead.", plainGameObject.name));
if (EditorUtility.IsPersistent(plainGameObject))
throw new ArgumentException("Input is from a Prefab asset, this is not supported. Input GameObject: " + plainGameObject.name, nameof(plainGameObject));
if (checkValidAsset)
ThrowIfInvalidAssetForReplacePrefabInstance(prefabAssetRoot, mode);
if (plainGameObject.transform.GetType() != prefabAssetRoot.transform.GetType())
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));
// Prefab Mode and EditPrefabContents scope handling
if (PrefabStageUtility.IsGameObjectThePrefabRootInAnyPrefabStage(plainGameObject) || (EditorSceneManager.IsPreviewSceneObject(plainGameObject) && plainGameObject.transform.parent == null))
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);
if (plainGameObject.hideFlags.HasFlag(HideFlags.DontSaveInEditor) || plainGameObject.transform.hideFlags.HasFlag(HideFlags.DontSaveInEditor))
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));
if (mode == InteractionMode.UserAction)
{
// Recording undo does not handle missing scripts
var gameObjectsWithInvalidScript = FindGameObjectsWithInvalidComponent(plainGameObject);
if (gameObjectsWithInvalidScript.Count > 0)
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."));
}
}
public static void ConvertToPrefabInstance(GameObject plainGameObject, GameObject prefabAssetRoot, ConvertToPrefabInstanceSettings settings, InteractionMode mode)
{
ThrowIfInvalidArgumentsForConvertToPrefabInstance(plainGameObject, prefabAssetRoot, true, mode);
ConvertToPrefabInstance_NoInputValidation(plainGameObject, prefabAssetRoot, settings, mode);
EditorUtility.ForceRebuildInspectors();
}View on GitHub (pinned to 225b0fbdb5)
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;
Example fix
// before PrefabUtility.ConvertToPrefabInstance(myGo, prefabAsset, settings, mode); // myGo has HideFlags.DontSaveInEditor // after myGo.hideFlags = HideFlags.None; myGo.transform.hideFlags = HideFlags.None; PrefabUtility.ConvertToPrefabInstance(myGo, prefabAsset, settings, mode);
Defensive patterns
Strategy: validation
Validate before calling
if (plainGameObject.hideFlags.HasFlag(HideFlags.DontSaveInEditor)
|| plainGameObject.transform.hideFlags.HasFlag(HideFlags.DontSaveInEditor))
{
plainGameObject.hideFlags = HideFlags.None;
plainGameObject.transform.hideFlags = HideFlags.None;
}
PrefabUtility.ConvertToPrefabInstance(plainGameObject, prefabAssetRoot, settings, mode); Type guard
static bool HasNoDontSaveFlag(GameObject obj)
{
return obj != null
&& !obj.hideFlags.HasFlag(HideFlags.DontSaveInEditor)
&& !obj.transform.hideFlags.HasFlag(HideFlags.DontSaveInEditor);
} Prevention
- Don't set DontSaveInEditor on objects targeted by Prefab conversion.
- Audit transient editor objects for stray hide flags before batch operations.
When it happens
Trigger: 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.
Common situations: Editor extensions that create helper objects with DontSaveInEditor. Objects left behind by deleted tools that still carry the flag.
Related errors
- Input instance root is using the HideFlags.DontSaveInEditor
- Input '{0}' is not a Prefab instance, for plain GameObjects
- Input instance is not an outermost Prefab instance root. Inp
- Input instance root is from a Prefab asset, this is not supp
- Replacing the root Prefab instance in a Variant is not suppo
AI-assisted analysis of Unity-Technologies/UnityCsReference@225b0fbdb5 (2026-08-13).
Data as JSON: /api/errors/b6c45eda7a5b3b25.
Report an issue: GitHub.