{"record":{"id":"569814d7032897f0","repo":"Unity-Technologies/UnityCsReference","slug":"array-is-invalid-569814","errorCode":null,"errorMessage":"Array is invalid.","messagePattern":"Array is invalid\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"Editor/Mono/Prefabs/PrefabUtility.cs","lineNumber":1735,"sourceCode":"\n                Analytics.SendApplyEvent(\n                    Analytics.ApplyScope.AddedGameObject,\n                    instanceRoot,\n                    assetPath,\n                    action,\n                    startTime,\n                    false\n                );\n            }\n\n            PrefabUtility.Internal_CallPrefabInstanceApplied(instanceRoot);\n            EditorUtility.ForceRebuildInspectors();\n        }\n\n        internal static bool HasSameParent(GameObject[] gameObjects)\n        {\n            if (gameObjects == null || gameObjects.Length == 0 || gameObjects[0] == null)\n                throw new ArgumentException(nameof(gameObjects), \"Array is invalid.\");\n\n            Transform goParent = gameObjects[0].transform.parent;\n\n            if (goParent == null)\n                throw new ArgumentException(nameof(goParent), \"Object is a parentless root.\");\n\n            foreach (GameObject go in gameObjects)\n            {\n                if (go.transform.parent != goParent)\n                    return false;\n            }\n\n            return true;\n        }\n\n        private static void RemoveRemovedGameObjectOverride(Object instanceObject, GameObject assetGameObject)\n        {\n            var removedGameObjects = PrefabUtility.GetRemovedGameObjects(instanceObject);","sourceCodeStart":1717,"sourceCodeEnd":1753,"githubUrl":"https://github.com/Unity-Technologies/UnityCsReference/blob/225b0fbdb57cc17d094e8056b71f8314aba56f73/Editor/Mono/Prefabs/PrefabUtility.cs#L1717-L1753","documentation":"Internal helper HasSameParent throws ArgumentException when the array is null, empty, or its first element is null. These are preconditions needed before comparing parents; without a valid first element there is no baseline parent to compare against.","triggerScenarios":"Reached internally by ApplyAddedGameObjects with a malformed array, or called directly with null/empty array or null first element. The public API normally guards these earlier, so reaching this throw indicates internal misuse or an unexpected call path.","commonSituations":"An upstream guard was bypassed; reflection or internal invocation called HasSameParent without the normal precondition checks; a bug in calling code passing an unfiltered array.","solutions":["Ensure callers validate the array (non-null, non-empty, first element non-null) before invoking; the public ApplyAddedGameObjects already does this, so reaching here suggests a bug.","If reached through normal API usage, report it as a Unity bug with the reproduction steps.","Avoid calling internal helpers directly; use the public API which performs the precondition checks."],"exampleFix":"// before (internal misuse)\nbool same = PrefabUtility.HasSameParent(maybeEmptyArray);\n\n// after\nif (maybeEmptyArray != null && maybeEmptyArray.Length > 0 && maybeEmptyArray[0] != null)\n    bool same = PrefabUtility.HasSameParent(maybeEmptyArray);","handlingStrategy":"validation","validationCode":"if (gameObjects == null || gameObjects.Length == 0 || gameObjects[0] == null)\n    return false;","typeGuard":"static bool IsValidArrayForParentCheck(GameObject[] gos) =>\n    gos != null && gos.Length > 0 && gos[0] != null;","tryCatchPattern":null,"preventionTips":["Do not call the internal HasSameParent helper directly; use the public API which pre-validates.","If you reach this throw via the public API, treat it as a Unity bug and file a report.","Always validate array shape before any parent-comparison logic."],"tags":["prefab","unity","internal","validation"],"backgroundTag":null,"analyzedSha":"225b0fbdb57cc17d094e8056b71f8314aba56f73","analyzedAt":"2026-08-13T19:07:19.849Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}