{"record":{"id":"7583f2024baff562","repo":"Unity-Technologies/UnityCsReference","slug":"instanceroot","errorCode":null,"errorMessage":"instanceRoot","messagePattern":"instanceRoot","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"Editor/Mono/Prefabs/PrefabUtility.cs","lineNumber":2765,"sourceCode":"        }\n\n        [RequiredByNativeCode]\n        internal static void Internal_CallPrefabInstanceReverted(GameObject instanceRoot)\n        {\n            Assert.IsNotNull(instanceRoot);\n\n            prefabInstanceReverted?.Invoke(instanceRoot);\n        }\n\n        [AutoStaticsCleanupOnCodeReload]\n        public static event Action<GameObject, PrefabUnpackMode> prefabInstanceUnpacking;\n        [AutoStaticsCleanupOnCodeReload]\n        public static event Action<GameObject, PrefabUnpackMode> prefabInstanceUnpacked;\n\n        public static void UnpackPrefabInstance(GameObject instanceRoot, PrefabUnpackMode unpackMode, InteractionMode action)\n        {\n            if (instanceRoot == null)\n                throw new ArgumentNullException(nameof(instanceRoot));\n\n            if (!IsPartOfNonAssetPrefabInstance(instanceRoot))\n                throw new ArgumentException(\"UnpackPrefabInstance must be called with a Prefab instance.\");\n\n            if (!IsOutermostPrefabInstanceRoot(instanceRoot))\n                throw new ArgumentException(\"UnpackPrefabInstance must be called with a root Prefab instance GameObject.\");\n\n            if (action == InteractionMode.UserAction)\n            {\n                var undoActionName = \"Unpack Prefab instance\";\n                Undo.RegisterFullObjectHierarchyUndo(instanceRoot, undoActionName);\n                var newInstanceRoots = UnpackPrefabInstanceAndReturnNewOutermostRoots(instanceRoot, unpackMode);\n                foreach (var newInstanceRoot in newInstanceRoots)\n                {\n                    var prefabInstance = PrefabUtility.GetPrefabInstanceHandle(newInstanceRoot);\n                    if (prefabInstance)\n                    {\n                        Undo.RegisterCreatedObjectUndo(prefabInstance, undoActionName);","sourceCodeStart":2747,"sourceCodeEnd":2783,"githubUrl":"https://github.com/Unity-Technologies/UnityCsReference/blob/225b0fbdb57cc17d094e8056b71f8314aba56f73/Editor/Mono/Prefabs/PrefabUtility.cs#L2747-L2783","documentation":"PrefabUtility.UnpackPrefabInstance throws an ArgumentNullException when instanceRoot is null. This method unpacks a prefab instance back into regular GameObjects and requires the root GameObject of the prefab instance.","triggerScenarios":"Calling PrefabUtility.UnpackPrefabInstance(null, unpackMode, action) where the first argument is null.","commonSituations":"Passing a destroyed GameObject, a reference that was set to null by a previous operation, or a field populated from a failed lookup (e.g., GetPrefabInstanceHandle returned null).","solutions":["Null-check instanceRoot before calling.","Verify the GameObject reference is valid using Unity's null comparison (handles destroyed objects).","Trace the source of instanceRoot to ensure it comes from a valid prefab instance lookup."],"exampleFix":"// before\nPrefabUtility.UnpackPrefabInstance(maybeNullGo, PrefabUnpackMode.OutermostRoot, InteractionMode.UserAction);\n// after\nif (instanceRoot != null)\n    PrefabUtility.UnpackPrefabInstance(instanceRoot, PrefabUnpackMode.OutermostRoot, InteractionMode.UserAction);","handlingStrategy":"validation","validationCode":"if (instanceRoot != null)\n    PrefabUtility.UnpackPrefabInstance(instanceRoot, PrefabUnpackMode.OutermostRoot, InteractionMode.UserAction);","typeGuard":"static bool IsValidInstanceRoot(GameObject go) => go != null;","tryCatchPattern":null,"preventionTips":["Check instanceRoot != null (Unity null check) before unpack","Trace the source of instanceRoot to ensure valid assignment","Use GetOutermostInstanceRoot result only after null check"],"tags":["unity","prefab","argument-null","editor"],"backgroundTag":null,"analyzedSha":"225b0fbdb57cc17d094e8056b71f8314aba56f73","analyzedAt":"2026-08-13T19:07:19.849Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}