{"record":{"id":"eb80a0795329dabf","repo":"Unity-Technologies/UnityCsReference","slug":"applyprefabaddedgameobjects-requires-that-gameobje-eb80a0","errorCode":null,"errorMessage":"ApplyPrefabAddedGameObjects requires that GameObjects share the same parent asset path.","messagePattern":"ApplyPrefabAddedGameObjects requires that GameObjects share the same parent asset path\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"Editor/Mono/GUI/TargetChoiceHandler.cs","lineNumber":139,"sourceCode":"            EditorUtility.ForceRebuildInspectors();\n        }\n\n        internal static void ApplyPrefabAddedGameObjects(object userData)\n        {\n            ObjectInstanceAndSourcePathInfo[] infos = (ObjectInstanceAndSourcePathInfo[])userData;\n\n            GameObject[] gameObjects = new GameObject[infos.Length];\n            for (int i = 0; i < infos.Length; i++)\n            {\n                ObjectInstanceAndSourcePathInfo info = infos[i];\n                gameObjects[i] = info.instanceObject as GameObject;\n            }\n\n            if (!PrefabUtility.HasSameParent(gameObjects))\n                throw new ArgumentException(nameof(gameObjects), \"ApplyPrefabAddedGameObjects requires that GameObjects share the same parent.\");\n\n            if (!HasSameAssetPath(infos))\n                throw new ArgumentException(nameof(infos), \"ApplyPrefabAddedGameObjects requires that GameObjects share the same parent asset path.\");\n\n            if (!PrefabUtility.PromptAndCheckoutPrefabIfNeeded(infos[0].assetPath, PrefabUtility.SaveVerb.Apply))\n                return;\n\n            PrefabUtility.ApplyAddedGameObjects(gameObjects, infos[0].assetPath, InteractionMode.UserAction);\n            EditorUtility.ForceRebuildInspectors();\n        }\n\n        internal static bool HasSameAssetPath(ObjectInstanceAndSourcePathInfo[] infos)\n        {\n            if (infos == null || infos.Length == 0)\n                throw new ArgumentException(nameof(infos), \"Array is invalid.\");\n\n            string assetPath = infos[0].assetPath;\n            for (int i = 1; i < infos.Length; i++)\n            {\n                if (assetPath != infos[i].assetPath)\n                    return false;","sourceCodeStart":121,"sourceCodeEnd":157,"githubUrl":"https://github.com/Unity-Technologies/UnityCsReference/blob/225b0fbdb57cc17d094e8056b71f8314aba56f73/Editor/Mono/GUI/TargetChoiceHandler.cs#L121-L157","documentation":"Thrown by ApplyPrefabAddedGameObjects when the supplied GameObjects originate from different prefab asset paths. HasSameAssetPath verifies every ObjectInstanceAndSourcePathInfo entry shares one assetPath, because a single apply call can only target one prefab asset.","triggerScenarios":"Selecting added GameObjects that come from more than one distinct prefab asset and invoking Apply; passing an infos array whose entries have differing assetPath values.","commonSituations":"Multi-selection spanning multiple prefab instances (different source assets); a script batching apply across unrelated prefabs for convenience.","solutions":["Partition the selection by assetPath and apply each asset group in its own call.","Verify all entries share infos[0].assetPath before calling the API and prompt the user otherwise.","Use HasSameAssetPath(infos) as a precondition guard and report the mismatched paths."],"exampleFix":"// before\nApplyPrefabAddedGameObjects(infos); // mixed asset paths\n\n// after\nforeach (var group in infos.GroupBy(i => i.assetPath))\n    ApplyPrefabAddedGameObjects(group.ToArray());","handlingStrategy":"validation","validationCode":"bool SameAssetPath(ObjectInstanceAndSourcePathInfo[] infos) => infos.All(i => i.assetPath == infos[0].assetPath);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Partition the selection by assetPath before apply.","Show the source asset in the Apply confirmation dialog so mismatches are visible.","Reject cross-asset apply at the UI layer."],"tags":["unity-editor","prefab","asset-path","argument"],"backgroundTag":null,"analyzedSha":"225b0fbdb57cc17d094e8056b71f8314aba56f73","analyzedAt":"2026-08-13T19:07:19.849Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}