{"record":{"id":"191bf547b2a7bce1","repo":"Unity-Technologies/UnityCsReference","slug":"no-gameobjects-in-array","errorCode":null,"errorMessage":"No GameObjects in array.","messagePattern":"No GameObjects in array\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"Editor/Mono/Prefabs/PrefabUtility.cs","lineNumber":1650,"sourceCode":"            );\n\n            PrefabUtility.Internal_CallPrefabInstanceApplied(prefabInstanceRoot);\n        }\n\n        public static void ApplyAddedGameObject(GameObject gameObject, string assetPath, InteractionMode action)\n        {\n            ApplyAddedGameObjects(new GameObject[] { gameObject}, assetPath, action);\n        }\n\n        public static void ApplyAddedGameObjects(GameObject[] gameObjects, string assetPath, InteractionMode action)\n        {\n            DateTime startTime = DateTime.UtcNow;\n\n            if (gameObjects == null)\n                throw new ArgumentNullException(nameof(gameObjects), \"Cannot apply added GameObjects. GameObjects array is null.\");\n\n            if (gameObjects.Length == 0)\n                throw new ArgumentException(nameof(gameObjects), \"No GameObjects in array.\");\n\n            foreach (GameObject go in gameObjects)\n            {\n                if (go == null)\n                    throw new ArgumentException(nameof(go), \"Input GameObject is null.\");\n\n                if (!IsAddedGameObjectOverride(go))\n                    throw new ArgumentException(nameof(go), $\"Cannot apply added GameObject. GameObject '{go.name}' is not an added GameObject override on a Prefab instance.\");\n\n                ThrowExceptionIfInstanceIsPersistent(go);\n            }\n\n            if (gameObjects.Length > 1 && !HasSameParent(gameObjects))\n                throw new ArgumentException(nameof(gameObjects), \"ApplyAddedGameObjects requires that GameObjects share the same parent.\");\n\n            GameObject gameObject = gameObjects[0];\n            Transform instanceParent = gameObject.transform.parent;\n            if (instanceParent == null)","sourceCodeStart":1632,"sourceCodeEnd":1668,"githubUrl":"https://github.com/Unity-Technologies/UnityCsReference/blob/225b0fbdb57cc17d094e8056b71f8314aba56f73/Editor/Mono/Prefabs/PrefabUtility.cs#L1632-L1668","documentation":"ApplyAddedGameObjects throws ArgumentException when the array contains zero elements. Applying nothing is not a meaningful operation, so the API rejects the empty array rather than silently no-op. Distinguished from a null array (581) by the non-null-but-empty state.","triggerScenarios":"Calling with new GameObject[0] or Array.Empty<GameObject>(); passing the result of a filtered selection that yielded no added overrides.","commonSituations":"Selection filtering removed all candidates (none were added overrides) and the empty result was forwarded unchecked; building arrays from user selection that ended up empty.","solutions":["Check gameObjects.Length > 0 before calling and skip when empty.","Use the singular ApplyAddedGameObject overload only when exactly one object is involved.","Surface 'nothing to apply' as a user message instead of forwarding an empty array."],"exampleFix":"// before\nPrefabUtility.ApplyAddedGameObjects(addedGos, path, mode);\n\n// after\nif (addedGos != null && addedGos.Length > 0)\n    PrefabUtility.ApplyAddedGameObjects(addedGos, path, mode);","handlingStrategy":"validation","validationCode":"if (gameObjects == null || gameObjects.Length == 0) return;","typeGuard":"static bool HasElements(GameObject[] gos) => gos != null && gos.Length > 0;","tryCatchPattern":null,"preventionTips":["Check Length > 0 before calling and surface 'nothing to apply' to the user.","Use ApplyAddedGameObject (singular) when exactly one object is involved.","Treat empty results as a no-op at the call site rather than forwarding them."],"tags":["prefab","unity","validation","empty-array"],"backgroundTag":null,"analyzedSha":"225b0fbdb57cc17d094e8056b71f8314aba56f73","analyzedAt":"2026-08-13T19:07:19.849Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}