{"record":{"id":"414599afd271bf2f","repo":"Unity-Technologies/UnityCsReference","slug":"provided-gameobject-is-not-a-prefab-instance","errorCode":null,"errorMessage":"Provided GameObject is not a Prefab instance","messagePattern":"Provided GameObject is not a Prefab instance","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"Editor/Mono/Prefabs/PrefabOverrides/PrefabOverridesUtility.cs","lineNumber":25,"sourceCode":"using UnityEngine;\nusing Unity.Scripting.LifecycleManagement;\n\nnamespace UnityEditor.SceneManagement\n{\n    internal class PrefabOverridesUtility\n    {\n        [NoAutoStaticsCleanup] // Reusable scratch buffer, always Clear()ed before and after use; holds no live references across reload.\n        static List<Component> s_ComponentList = new List<Component>();\n        [NoAutoStaticsCleanup] // Reusable scratch buffer, always Clear()ed before and after use; holds no live references across reload.\n        static List<Component> s_AssetComponentList = new List<Component>();\n\n        static void ThrowExceptionIfNullOrNotPartOfPrefabInstance(GameObject prefabInstance)\n        {\n            if (prefabInstance == null)\n                throw new ArgumentNullException(nameof(prefabInstance));\n\n            if (!PrefabUtility.IsPartOfPrefabInstance(prefabInstance))\n                throw new ArgumentException(\"Provided GameObject is not a Prefab instance\");\n        }\n\n        public static List<ObjectOverride> GetObjectOverrides(GameObject prefabInstance, bool includeDefaultOverrides = false)\n        {\n            ThrowExceptionIfNullOrNotPartOfPrefabInstance(prefabInstance);\n\n            var prefabInstanceRoot = PrefabUtility.GetOutermostPrefabInstanceRoot(prefabInstance);\n\n            // From root of instance traverse all child go and detect any GameObjects or components\n            // that are not part of that source prefab objects component list (these must be added)\n            TransformVisitor transformVisitor = new TransformVisitor();\n            var modifiedObjects = new List<ObjectOverride>();\n\n            Func<Transform, object, bool> checkMethod;\n            if (includeDefaultOverrides)\n                checkMethod = CheckForModifiedObjectsIncludingDefaultOverrides;\n            else\n                checkMethod = CheckForModifiedObjectsExcludingDefaultOverrides;","sourceCodeStart":7,"sourceCodeEnd":43,"githubUrl":"https://github.com/Unity-Technologies/UnityCsReference/blob/225b0fbdb57cc17d094e8056b71f8314aba56f73/Editor/Mono/Prefabs/PrefabOverrides/PrefabOverridesUtility.cs#L7-L43","documentation":"PrefabOverridesUtility.ThrowExceptionIfNullOrNotPartOfPrefabInstance is the precondition guard called by GetObjectOverrides and related methods. It throws ArgumentException(\"Provided GameObject is not a Prefab instance\") when the passed GameObject is not part of a prefab instance (i.e., PrefabUtility.IsPartOfPrefabInstance returns false). This covers both plain scene objects and prefab assets, since overrides only exist on prefab instances.","triggerScenarios":"Calling PrefabOverridesUtility.GetObjectOverrides on a plain scene GameObject, a prefab asset in the Project window, or any object that PrefabUtility.IsPartOfPrefabInstance returns false for.","commonSituations":"Editor tools that operate on the current selection without verifying it is a prefab instance. Code that handles both prefab assets and instances in the same path. Unpacking a prefab instance and then trying to query its overrides.","solutions":["Call PrefabUtility.IsPartOfPrefabInstance(go) before passing the GameObject to GetObjectOverrides","If the object might be a prefab asset, use PrefabUtility.IsPartOfPrefabAsset to distinguish and route accordingly","Validate Selection.activeGameObject or the user-provided object before processing"],"exampleFix":"// before\nvar overrides = PrefabOverridesUtility.GetObjectOverrides(selectedGo);\n\n// after\nif (selectedGo != null && PrefabUtility.IsPartOfPrefabInstance(selectedGo))\n    var overrides = PrefabOverridesUtility.GetObjectOverrides(selectedGo);\nelse\n    Debug.LogWarning(\"Selection is not a prefab instance.\");","handlingStrategy":"validation","validationCode":"if (!PrefabUtility.IsPartOfPrefabInstance(prefabInstance))\n{\n    Debug.LogWarning(\"GameObject is not a prefab instance — overrides are not applicable.\");\n    return;\n}\n// Safe to call GetObjectOverrides(prefabInstance)","typeGuard":"static bool IsPrefabInstance(GameObject go) => go != null && PrefabUtility.IsPartOfPrefabInstance(go);","tryCatchPattern":"try { var overrides = PrefabOverridesUtility.GetObjectOverrides(go); }\ncatch (ArgumentException ex) when (ex.Message == \"Provided GameObject is not a Prefab instance\")\n{ Debug.LogWarning($\"{go.name} is not a prefab instance.\"); }","preventionTips":["Always call PrefabUtility.IsPartOfPrefabInstance before querying overrides","Distinguish prefab assets from prefab instances using IsPartOfPrefabAsset vs IsPartOfPrefabInstance","Validate user selections before processing prefab operations"],"tags":["unity","editor-scripting","prefab","validation","prefab-instance","argumentexception"],"backgroundTag":null,"analyzedSha":"225b0fbdb57cc17d094e8056b71f8314aba56f73","analyzedAt":"2026-08-13T19:07:19.849Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}