{"record":{"id":"d6e606f35f56a841","repo":"Unity-Technologies/UnityCsReference","slug":"can-t-save-part-of-a-prefab-instance-as-a-prefab","errorCode":null,"errorMessage":"Can't save part of a Prefab instance as a Prefab","messagePattern":"Can't save part of a Prefab instance as a Prefab","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"Editor/Mono/Prefabs/PrefabUtility.cs","lineNumber":2093,"sourceCode":"\n            if (EditorUtility.IsPersistent(instanceRoot) && connectToInstance)\n                throw new ArgumentException(\"Can't save persistent Objects and connect them to the saved Prefab\");\n\n            if (IsPartOfNonAssetPrefabInstance(instanceRoot))\n            {\n                // A PrefabInstance with missing asset can be correctly restored only if CorrespondingObjects info is available\n                // 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)\n                var mergeStatus = GetMergeStatus(instanceRoot);\n                var hasCorrespondingSourceObjectInfo = mergeStatus == MergeStatus.NormalMerge || mergeStatus == MergeStatus.MergedAsMissingWithSceneBackup;\n                if (IsPrefabAssetMissing(instanceRoot) && !hasCorrespondingSourceObjectInfo)\n                    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.\");\n            }\n\n            var actualInstanceRoot = GetOutermostPrefabInstanceRoot(instanceRoot);\n            if (actualInstanceRoot)\n            {\n                if (actualInstanceRoot != instanceRoot)\n                    throw new ArgumentException(\"Can't save part of a Prefab instance as a Prefab\");\n            }\n\n            ValidatePath(instanceRoot, path);\n        }\n\n        private static void ReplacePrefabArgumentCheck(GameObject root, string path)\n        {\n            if (root == null)\n                throw new ArgumentNullException(\"Parameter root is null\");\n\n            ValidatePath(root, path);\n        }\n\n        public static GameObject SaveAsPrefabAsset(GameObject instanceRoot, string assetPath, out bool success)\n        {\n            SaveAsPrefabAssetArgumentCheck(instanceRoot, assetPath, false);\n\n            return SaveAsPrefabAsset_Internal(instanceRoot, assetPath, out success);","sourceCodeStart":2075,"sourceCodeEnd":2111,"githubUrl":"https://github.com/Unity-Technologies/UnityCsReference/blob/225b0fbdb57cc17d094e8056b71f8314aba56f73/Editor/Mono/Prefabs/PrefabUtility.cs#L2075-L2111","documentation":"Thrown by SaveAsPrefabAssetArgumentCheck when GetOutermostPrefabInstanceRoot(instanceRoot) returns a different object than instanceRoot. This means the passed GameObject is a descendant inside a Prefab instance, not the instance's root. Prefab save operations require the outermost root as the entry point.","triggerScenarios":"Passing a child or descendant of a Prefab instance to SaveAsPrefabAsset instead of the instance root. E.g. selecting a nested child in the hierarchy and trying to save it as a standalone Prefab while it's still nested.","commonSituations":"Developer grabs a specific child via transform.GetChild or Transform.Find and tries to save it directly. Selection.activeGameObject points at a non-root nested object. Misunderstanding of outermost-root semantics in nested Prefabs.","solutions":["Get the outermost root first: GameObject root = PrefabUtility.GetOutermostPrefabInstanceRoot(instanceRoot); then pass root.","If you want to save just the child, detach it from the instance (or duplicate it outside the instance) before saving.","Use Selection.activeTransform.root or verify PrefabUtility.IsOutermostPrefabInstanceRoot before calling save."],"exampleFix":"// before\nGameObject child = transform.Find(\"Arm/Hand\").gameObject;\nPrefabUtility.SaveAsPrefabAsset(child, \"Assets/h.prefab\");\n// after\nGameObject root = PrefabUtility.GetOutermostPrefabInstanceRoot(child) ?? child;\nPrefabUtility.SaveAsPrefabAsset(root, \"Assets/root.prefab\");","handlingStrategy":"validation","validationCode":"GameObject ResolveRoot(GameObject go)\n{\n    GameObject outer = PrefabUtility.GetOutermostPrefabInstanceRoot(go);\n    return outer != null ? outer : go;\n}","typeGuard":"static bool IsPrefabInstanceRoot(GameObject go) =>\n    go != null &&\n    PrefabUtility.GetOutermostPrefabInstanceRoot(go) == go;","tryCatchPattern":null,"preventionTips":["Always resolve the outermost root before calling SaveAsPrefabAsset.","Use Selection.activeTransform.root in editor scripts to target roots.","Check IsOutermostPrefabInstanceRoot for nested Prefab workflows."],"tags":["unity","prefab","nested-prefab","argument-check"],"backgroundTag":null,"analyzedSha":"225b0fbdb57cc17d094e8056b71f8314aba56f73","analyzedAt":"2026-08-13T19:07:19.849Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}