{"record":{"id":"5b7e832bab43fa60","repo":"Unity-Technologies/UnityCsReference","slug":"parameter-root-is-null","errorCode":null,"errorMessage":"Parameter root is null","messagePattern":"Parameter root is null","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"Editor/Mono/Prefabs/PrefabUtility.cs","lineNumber":2074,"sourceCode":"            if (isValidAssetFolder && isImmutableFolder)\n                throw new ArgumentException(\"Saving Prefab to immutable folder is not allowed: '\" + path + \"'\");\n\n            if (directory.Length > 0 && !Directory.Exists(directory))\n                throw new ArgumentException(\"Given path does not exist: '\" + path + \"'\");\n\n            if (isValidAssetFolder)\n            {\n                string projectRelativePath = Path.IsPathRooted(path) ? FileUtil.GetProjectRelativePath(path) : path;\n                string prefabGUID = AssetDatabase.AssetPathToGUID(projectRelativePath);\n                if (!VerifyNestingFromScript(new GameObject[] { instanceRoot }, prefabGUID, PrefabUtility.GetPrefabInstanceHandle(instanceRoot)))\n                    throw new ArgumentException(\"Cyclic nesting detected\");\n            }\n        }\n\n        private static void SaveAsPrefabAssetArgumentCheck(GameObject instanceRoot, string path, bool connectToInstance)\n        {\n            if (instanceRoot == null)\n                throw new ArgumentNullException(\"Parameter root is null\");\n\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)","sourceCodeStart":2056,"sourceCodeEnd":2092,"githubUrl":"https://github.com/Unity-Technologies/UnityCsReference/blob/225b0fbdb57cc17d094e8056b71f8314aba56f73/Editor/Mono/Prefabs/PrefabUtility.cs#L2056-L2092","documentation":"Thrown by SaveAsPrefabAssetArgumentCheck when instanceRoot is null. This is the first guard before any path or Prefab-state validation — the method cannot operate on a null GameObject reference.","triggerScenarios":"Calling SaveAsPrefabAsset or SaveAsPrefabAssetAndConnect with instanceRoot == null, typically because a GameObject lookup (GameObject.Find, transform.GetChild, etc.) returned null before the call.","commonSituations":"GameObject.Find returned null due to inactive object or wrong name. A serialized reference was not assigned in the Inspector. The object was destroyed between lookup and save call.","solutions":["Null-check instanceRoot before calling SaveAsPrefabAsset.","Verify the GameObject lookup (Find, transform.GetChild index, selection) returns the expected object.","Ensure the reference is assigned via Inspector or properly initialized in code."],"exampleFix":"// before\nGameObject go = GameObject.Find(\"MyObj\");\nPrefabUtility.SaveAsPrefabAsset(go, \"Assets/x.prefab\");\n// after\nGameObject go = GameObject.Find(\"MyObj\");\nif (go != null)\n    PrefabUtility.SaveAsPrefabAsset(go, \"Assets/x.prefab\");","handlingStrategy":"type-guard","validationCode":"if (instanceRoot == null)\n    throw new ArgumentNullException(nameof(instanceRoot));\nPrefabUtility.SaveAsPrefabAsset(instanceRoot, path);","typeGuard":"static bool IsSaveablePrefabSource(GameObject go) =>\n    go != null && go.scene.rootCount >= 0;","tryCatchPattern":null,"preventionTips":["Null-check every GameObject before passing to Prefab save APIs.","Log a meaningful error when lookups return null rather than passing it through.","Use [MenuItem] validation functions to disable commands when selection is null."],"tags":["unity","prefab","null-reference","argument-check"],"backgroundTag":null,"analyzedSha":"225b0fbdb57cc17d094e8056b71f8314aba56f73","analyzedAt":"2026-08-13T19:07:19.849Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}