{"record":{"id":"b8b0c4e9f88b5a3f","repo":"Unity-Technologies/UnityCsReference","slug":"can-t-save-a-model-prefab","errorCode":null,"errorMessage":"Can't save a Model Prefab","messagePattern":"Can't save a Model Prefab","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"Editor/Mono/Prefabs/PrefabUtility.cs","lineNumber":2022,"sourceCode":"            var assetObject = SaveAsPrefabAsset(empty, path, out success);\n            Object.DestroyImmediate(empty);\n            return PrefabUtility.GetPrefabObject(assetObject);\n        }\n\n        public static GameObject SavePrefabAsset(GameObject asset)\n        {\n            bool savedSuccesfully;\n            return SavePrefabAsset(asset, out savedSuccesfully);\n        }\n\n        public static GameObject SavePrefabAsset(GameObject asset, out bool savedSuccessfully)\n        {\n            if (asset == null)\n                throw new ArgumentNullException(\"Parameter prefabAssetGameObject is null\");\n\n            // Include model check even though models are also immutable, since we can give a more clear exception message.\n            if (IsPartOfModelPrefab(asset))\n                throw new ArgumentException(\"Can't save a Model Prefab\");\n\n            if (IsPartOfImmutablePrefab(asset))\n                throw new ArgumentException(\"Can't save an immutable Prefab\");\n\n            string path = AssetDatabase.GetAssetPath(asset);\n            if (String.IsNullOrEmpty(path))\n                throw new ArgumentException(\"Can't save a Prefab instance\");\n\n            var root = asset.transform.root.gameObject;\n            if (root != asset)\n                throw new ArgumentException(\"GameObject to save Prefab from must be a Prefab root\");\n\n            return SavePrefabAsset_Internal(root, out savedSuccessfully);\n        }\n\n        internal static void ValidatePath(GameObject instanceRoot, string path)\n        {\n            if (String.IsNullOrEmpty(path))","sourceCodeStart":2004,"sourceCodeEnd":2040,"githubUrl":"https://github.com/Unity-Technologies/UnityCsReference/blob/225b0fbdb57cc17d094e8056b71f8314aba56f73/Editor/Mono/Prefabs/PrefabUtility.cs#L2004-L2040","documentation":"SavePrefabAsset throws ArgumentException for model prefabs — prefabs imported from a 3D model file (FBX, DAE, OBJ, etc.). Model prefabs are immutable because their contents are regenerated from the source asset on reimport, so saving would be overwritten and is disallowed. The model check runs before the generic immutable check to give a clearer message.","triggerScenarios":"Calling SavePrefabAsset on a GameObject that is part of a model-imported prefab (IsPartOfModelPrefab returns true).","commonSituations":"Selecting an imported 3D model's hierarchy and attempting to save edits back to it; scripts that operate on arbitrary prefab assets without filtering model prefabs.","solutions":["Create a prefab variant of the model prefab and edit the variant, or unpack the model prefab into a regular prefab under Assets/.","Edit the source model file in the external DCC tool and reimport, instead of saving in Unity.","Filter with !PrefabUtility.IsPartOfModelPrefab(asset) before attempting to save."],"exampleFix":"// before\nPrefabUtility.SavePrefabAsset(modelPrefabRoot);\n\n// after\nif (PrefabUtility.IsPartOfModelPrefab(modelPrefabRoot))\n    PrefabUtility.SaveAsPrefabAsset(modelPrefabRoot, \"Assets/MyModelCopy.prefab\");\nelse\n    PrefabUtility.SavePrefabAsset(modelPrefabRoot);","handlingStrategy":"validation","validationCode":"if (PrefabUtility.IsPartOfModelPrefab(asset))\n{\n    // create a variant or copy instead\n    return;\n}","typeGuard":"static bool IsSaveablePrefab(GameObject asset) =>\n    asset != null && !PrefabUtility.IsPartOfModelPrefab(asset)\n    && !PrefabUtility.IsPartOfImmutablePrefab(asset);","tryCatchPattern":null,"preventionTips":["Filter out model prefabs with IsPartOfModelPrefab before saving.","Edit imported 3D models in the source DCC file, not via SavePrefabAsset.","Create a variant or unpack model prefabs into regular prefabs for editing."],"tags":["prefab","unity","model","immutable"],"backgroundTag":null,"analyzedSha":"225b0fbdb57cc17d094e8056b71f8314aba56f73","analyzedAt":"2026-08-13T19:07:19.849Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}