{"record":{"id":"5a809c193cf0d74a","repo":"Unity-Technologies/UnityCsReference","slug":"provided-gameobject-is-not-a-prefab-instance-5a809c","errorCode":null,"errorMessage":"Provided GameObject is not a Prefab instance","messagePattern":"Provided GameObject is not a Prefab instance","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"Editor/Mono/Prefabs/PrefabUtility.cs","lineNumber":2168,"sourceCode":"            }\n\n            return assetRoot;\n        }\n\n        internal static void ApplyPrefabInstance(GameObject instance)\n        {\n            if (instance == null)\n                throw new ArgumentNullException(nameof(instance));\n\n            // Include model check even though models are also immutable, since we can give a more clear exception message.\n            if (IsPartOfModelPrefab(instance))\n                throw new ArgumentException(\"Can't apply to a Model Prefab\");\n\n            if (IsPartOfImmutablePrefab(instance))\n                throw new ArgumentException(\"Can't apply to an immutable Prefab\");\n\n            if (!IsPartOfNonAssetPrefabInstance(instance))\n                throw new ArgumentException(\"Provided GameObject is not a Prefab instance\");\n\n            var root = GetOutermostPrefabInstanceRoot(instance);\n            if (root != instance)\n                throw new ArgumentException(\"GameObject to save Prefab from must be a Prefab root\");\n\n            var assetObject = GetCorrespondingObjectFromSource(instance);\n            string path = AssetDatabase.GetAssetPath(assetObject);\n\n            SaveAsPrefabAssetArgumentCheck(instance, path, true);\n\n            Internal_CallPrefabInstanceApplying(instance);\n\n            ApplyPrefabInstance_Internal(instance);\n\n            Internal_CallPrefabInstanceApplied(instance);\n        }\n\n        // Can't use UnityUpgradable since it doesn't currently support swapping parameter order.","sourceCodeStart":2150,"sourceCodeEnd":2186,"githubUrl":"https://github.com/Unity-Technologies/UnityCsReference/blob/225b0fbdb57cc17d094e8056b71f8314aba56f73/Editor/Mono/Prefabs/PrefabUtility.cs#L2150-L2186","documentation":"Thrown by ApplyPrefabInstance when the provided GameObject is not part of any non-asset Prefab instance (IsPartOfNonAssetPrefabInstance returns false). ApplyPrefabInstance only operates on scene-level Prefab instances; a plain GameObject or a Prefab asset itself is not eligible.","triggerScenarios":"Calling ApplyPrefabInstance on a plain GameObject (never connected to a Prefab) or directly on a Prefab asset in the project view.","commonSituations":"Developer passes an arbitrary scene GameObject that was never a Prefab instance. Confusing ApplyAddedComponent/ApplyObjectOverride with ApplyPrefabInstance. Calling apply on a newly created GameObject before connecting it to a Prefab.","solutions":["Confirm the GameObject is a Prefab instance: PrefabUtility.IsPartOfNonAssetPrefabInstance(go) before calling.","If it's a plain GameObject, connect it to a Prefab first or use the appropriate per-override apply API.","If it's a Prefab asset, edit it in Prefab Mode instead of using ApplyPrefabInstance."],"exampleFix":"// before\nPrefabUtility.ApplyPrefabInstance(plainGameObject);\n// after\nif (PrefabUtility.IsPartOfNonAssetPrefabInstance(plainGameObject))\n    PrefabUtility.ApplyPrefabInstance(plainGameObject);\nelse\n    Debug.LogWarning(\"Object is not a prefab instance.\");","handlingStrategy":"type-guard","validationCode":"if (!PrefabUtility.IsPartOfNonAssetPrefabInstance(go))\n{ Debug.LogError(\"Object is not a prefab instance.\"); return; }\nPrefabUtility.ApplyPrefabInstance(go);","typeGuard":"static bool IsNonAssetPrefabInstance(GameObject go) =>\n    go != null && PrefabUtility.IsPartOfNonAssetPrefabInstance(go);","tryCatchPattern":null,"preventionTips":["Confirm the GameObject is a scene-level Prefab instance before apply.","Distinguish plain GameObjects from Prefab instances in selection logic.","Use per-override apply APIs (ApplyAddedComponent, etc.) for granular control."],"tags":["unity","prefab","instance-check","apply"],"backgroundTag":null,"analyzedSha":"225b0fbdb57cc17d094e8056b71f8314aba56f73","analyzedAt":"2026-08-13T19:07:19.849Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}