{"record":{"id":"b97d1b0662b45bcc","repo":"Unity-Technologies/UnityCsReference","slug":"cannot-save-as-new-prefab-using-the-same-path","errorCode":null,"errorMessage":"Cannot save as new prefab using the same path","messagePattern":"Cannot save as new prefab using the same path","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"Editor/Mono/SceneManagement/StageManager/PrefabStage/PrefabStage.cs","lineNumber":1503,"sourceCode":"                m_IgnoreNextAssetImportedEventForCurrentPrefab = false;\n            }\n\n            if (SceneHierarchy.s_DebugPrefabStage)\n                Debug.Log(\"SAVE PREFAB ended\");\n\n            showingSavingLabel = false;\n\n            return savedSuccesfully;\n        }\n\n        internal bool SaveAsNew(string newPath, bool asCopy)\n        {\n            if (!isValid)\n                return false;\n\n            if (newPath == m_PrefabAssetPath)\n            {\n                throw new ArgumentException(\"Cannot save as new prefab using the same path\");\n            }\n\n            if (asCopy)\n            {\n                // Keep current open prefab and save copy at newPath\n                string oldName = m_PrefabContentsRoot.name;\n                m_PrefabContentsRoot.name = Path.GetFileNameWithoutExtension(newPath);\n                PrefabUtility.SaveAsPrefabAsset(m_PrefabContentsRoot, newPath);\n                m_PrefabContentsRoot.name = oldName;\n            }\n            else\n            {\n                // Change the current open prefab and save\n                m_PrefabContentsRoot.name = Path.GetFileNameWithoutExtension(newPath);\n                m_PrefabAssetPath = newPath;\n                CachePrefabFolderInfo();\n                ClearDirtiness();\n                PrefabUtility.SaveAsPrefabAsset(m_PrefabContentsRoot, newPath);","sourceCodeStart":1485,"sourceCodeEnd":1521,"githubUrl":"https://github.com/Unity-Technologies/UnityCsReference/blob/225b0fbdb57cc17d094e8056b71f8314aba56f73/Editor/Mono/SceneManagement/StageManager/PrefabStage/PrefabStage.cs#L1485-L1521","documentation":"Thrown by PrefabStage.SaveAsNew when newPath equals the current m_PrefabAssetPath. Saving as a new prefab requires a distinct destination path; reusing the current path is an error because SaveAsNew is meant to create a new asset, not overwrite the existing one (use Save() for that).","triggerScenarios":"Calling SaveAsNew with the same path as the currently open prefab. Path comparison failing to normalize, e.g., passing a path that resolves to the same asset after canonicalization but differs textually (though the guard does exact string comparison).","commonSituations":"Automated tooling that derives newPath from the current asset path and accidentally lands on the same value. Copy/paste of a path without changing the filename. UI flow where 'Save As' defaults to the current path.","solutions":["Ensure newPath is a different path than the current prefab asset path; use a distinct filename or folder.","If you intend to overwrite the existing prefab, call Save() instead of SaveAsNew().","Normalize both paths (Path.GetFullPath) before comparison if path formatting differs."],"exampleFix":"// before\nstage.SaveAsNew(stage.assetPath, asCopy: false);\n\n// after\nstring newPath = stage.assetPath.Replace(\".prefab\", \"_Variant.prefab\");\nif (newPath != stage.assetPath)\n    stage.SaveAsNew(newPath, asCopy: false);","handlingStrategy":"validation","validationCode":"if (string.Equals(newPath, stage.assetPath, StringComparison.OrdinalIgnoreCase))\n    throw new InvalidOperationException(\"Use Save() to overwrite the current prefab.\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Derive SaveAsNew paths by changing the filename, not the directory.","Use stage.Save() when the intent is to overwrite the existing prefab."],"tags":["unity","prefab","editor","validation"],"backgroundTag":null,"analyzedSha":"225b0fbdb57cc17d094e8056b71f8314aba56f73","analyzedAt":"2026-08-13T19:07:19.849Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}