Unity-Technologies/UnityCsReference · error · ArgumentException
Can't save persistent Objects and connect them to the saved
Error message
Can't save persistent Objects and connect them to the saved Prefab
What it means
Thrown by SaveAsPrefabAssetArgumentCheck when the instanceRoot is a persistent object (EditorUtility.IsPersistent returns true) and connectToInstance is true. Persistent objects live in the AssetDatabase, not in a scene, so connecting them to a scene instance is meaningless and disallowed.
Source
Thrown at Editor/Mono/Prefabs/PrefabUtility.cs:2077
if (directory.Length > 0 && !Directory.Exists(directory))
throw new ArgumentException("Given path does not exist: '" + path + "'");
if (isValidAssetFolder)
{
string projectRelativePath = Path.IsPathRooted(path) ? FileUtil.GetProjectRelativePath(path) : path;
string prefabGUID = AssetDatabase.AssetPathToGUID(projectRelativePath);
if (!VerifyNestingFromScript(new GameObject[] { instanceRoot }, prefabGUID, PrefabUtility.GetPrefabInstanceHandle(instanceRoot)))
throw new ArgumentException("Cyclic nesting detected");
}
}
private static void SaveAsPrefabAssetArgumentCheck(GameObject instanceRoot, string path, bool connectToInstance)
{
if (instanceRoot == null)
throw new ArgumentNullException("Parameter root is null");
if (EditorUtility.IsPersistent(instanceRoot) && connectToInstance)
throw new ArgumentException("Can't save persistent Objects and connect them to the saved Prefab");
if (IsPartOfNonAssetPrefabInstance(instanceRoot))
{
// A PrefabInstance with missing asset can be correctly restored only if CorrespondingObjects info is available
// CorrespondingObject info is available when a PrefabInstance with missing asset was merged before deleting the asset (kNormalMerge) or when it has a scene backup (kMergedAsMissingWithSceneBackup)
var mergeStatus = GetMergeStatus(instanceRoot);
var hasCorrespondingSourceObjectInfo = mergeStatus == MergeStatus.NormalMerge || mergeStatus == MergeStatus.MergedAsMissingWithSceneBackup;
if (IsPrefabAssetMissing(instanceRoot) && !hasCorrespondingSourceObjectInfo)
throw new ArgumentException("Can't save Prefab instance with missing asset and scene backup as a Prefab. You may unpack the instance and save the unpacked GameObjects as a Prefab.");
}
var actualInstanceRoot = GetOutermostPrefabInstanceRoot(instanceRoot);
if (actualInstanceRoot)
{
if (actualInstanceRoot != instanceRoot)
throw new ArgumentException("Can't save part of a Prefab instance as a Prefab");
}
View on GitHub (pinned to 225b0fbdb5)
Solutions
- Use SaveAsPrefabAsset (without connect) when operating on an existing asset, not SaveAsPrefabAssetAndConnect.
- If you need a connected scene instance, first instantiate the asset into a scene then save/connect from there.
- Check EditorUtility.IsPersistent(instanceRoot) before calling the connect variant.
Example fix
// before
GameObject asset = AssetDatabase.LoadAssetAtPath<GameObject>("Assets/x.prefab");
PrefabUtility.SaveAsPrefabAssetAndConnect(asset, "Assets/y.prefab", InteractionMode.AutomatedAction);
// after
GameObject asset = AssetDatabase.LoadAssetAtPath<GameObject>("Assets/x.prefab");
PrefabUtility.SaveAsPrefabAsset(asset, "Assets/y.prefab"); Defensive patterns
Strategy: validation
Validate before calling
void SavePrefabAuto(GameObject go, string path, bool connect)
{
if (connect && EditorUtility.IsPersistent(go))
{
Debug.LogWarning("Object is persistent; using SaveAsPrefabAsset (no connect).");
PrefabUtility.SaveAsPrefabAsset(go, path);
}
else if (connect)
PrefabUtility.SaveAsPrefabAssetAndConnect(go, path, InteractionMode.AutomatedAction);
else
PrefabUtility.SaveAsPrefabAsset(go, path);
} Type guard
static bool CanConnectToScene(GameObject go) =>
go != null && !EditorUtility.IsPersistent(go); Prevention
- Reserve SaveAsPrefabAssetAndConnect for scene-level instances only.
- Check EditorUtility.IsPersistent before choosing the connect variant.
- Document clearly which API each helper uses to avoid misuse.
When it happens
Trigger: Calling SaveAsPrefabAssetAndConnect (which passes connectToInstance=true) with a GameObject that is already an asset (e.g. a Prefab asset loaded via AssetDatabase.LoadAssetAtPath), rather than a scene-level instance.
Common situations: Developer loads a Prefab asset and tries to "save and connect" it, not realizing connect is a scene-instance operation. Confusion between SaveAsPrefabAsset (no connect) and SaveAsPrefabAssetAndConnect (connect).
Related errors
- Parameter root is null
- Can't save Prefab instance with missing asset and scene back
- Can't save part of a Prefab instance as a Prefab
- PrefabFamilyPopup is already open
- guid
AI-assisted analysis of Unity-Technologies/UnityCsReference@225b0fbdb5 (2026-08-13).
Data as JSON: /api/errors/1fa5a5e9691fd004.
Report an issue: GitHub.