{"record":{"id":"81f15b5262d3f304","repo":"Unity-Technologies/UnityCsReference","slug":"cannot-apply-or-revert-on-any-of-the-objects-atte","errorCode":null,"errorMessage":"Cannot apply or revert on any of the objects. Attempt with individual objects for details.","messagePattern":"Cannot apply or revert on any of the objects\\. Attempt with individual objects for details\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"Editor/Mono/Prefabs/PrefabUtility.cs","lineNumber":265,"sourceCode":"                throw new NullReferenceException(\"Cannot apply or revert object. Object is null.\");\n            if (!PrefabUtility.IsPartOfPrefabInstance(prefabInstanceObject))\n                throw new ArgumentException(\"Calling apply or revert methods on an object which is not part of a Prefab instance is not supported.\", nameof(prefabInstanceObject));\n\n            // We support revert operations on Prefab Assets, but not apply operations.\n            if (isApply)\n                ThrowExceptionIfInstanceIsPersistent(prefabInstanceObject);\n        }\n\n        static void ThrowExceptionIfAllPrefabInstanceObjectsAreInvalid(Object[] prefabInstanceObjects, bool isApply)\n        {\n            foreach (var obj in prefabInstanceObjects)\n            {\n                if (obj != null && (obj is GameObject || obj is Component) && IsPartOfPrefabInstance(obj) && !(isApply && EditorUtility.IsPersistent(obj)))\n                    return;\n            }\n\n            // Throw exception if all objects are invalid\n            throw new ArgumentException(\"Cannot apply or revert on any of the objects. Attempt with individual objects for details.\", nameof(prefabInstanceObjects));\n        }\n\n        static void ThrowExceptionIfInstanceIsPersistent(Object prefabInstanceObject)\n        {\n            if (EditorUtility.IsPersistent(prefabInstanceObject))\n                throw new ArgumentException(\"Calling apply methods on an instance which is part of a Prefab Asset is not supported.\", nameof(prefabInstanceObject));\n        }\n\n        public static GameObject[] FindAllInstancesOfPrefab(GameObject prefabRoot)\n        {\n            return FindAllInstancesOfPrefab_internal(prefabRoot, SceneHandle.None);\n        }\n\n        public static GameObject[] FindAllInstancesOfPrefab(GameObject prefabRoot, Scene scene)\n        {\n            if (!scene.IsValid())\n            {\n                throw new ArgumentException(\"Input scene is not valid: Could not be found.\");","sourceCodeStart":247,"sourceCodeEnd":283,"githubUrl":"https://github.com/Unity-Technologies/UnityCsReference/blob/225b0fbdb57cc17d094e8056b71f8314aba56f73/Editor/Mono/Prefabs/PrefabUtility.cs#L247-L283","documentation":"Thrown by ThrowExceptionIfAllPrefabInstanceObjectsAreInvalid when none of the objects in the input array pass the validity filter (non-null, GameObject/Component, IsPartOfPrefabInstance, and not persistent-when-applying). It is a bulk variant: rather than failing on the first invalid item, Unity reports that the entire batch is unusable and suggests retrying individually for details.","triggerScenarios":"Calling an array-based apply/revert overload where every element is null, not a GameObject/Component, not part of a prefab instance, or (for apply) persistent/prefab-asset objects.","commonSituations":"Bulk editor operations on a selection that contains only invalid items. Passing an array of asset-side objects to an apply-all method. Applying to a list where all entries were unpacked.","solutions":["Filter the array to valid objects before calling the bulk API.","Retry with individual objects to identify which specific check each fails.","Pre-validate each element with the same predicate Unity uses (non-null + GameObject/Component + IsPartOfPrefabInstance + not persistent for apply)."],"exampleFix":"// before\nPrefabUtility.ApplyPrefabOverride(allInvalidObjs, path); // throws\n\n// after\nvar valid = objs.Where(o => o != null && (o is GameObject || o is Component)\n    && PrefabUtility.IsPartOfPrefabInstance(o)\n    && !EditorUtility.IsPersistent(o)).ToArray();\nif (valid.Length == 0) { Debug.LogWarning(\"No valid objects.\"); return; }\nPrefabUtility.ApplyPrefabOverride(valid, path);","handlingStrategy":"validation","validationCode":"var valid = objs.Where(o => o != null && (o is GameObject || o is Component)\n    && PrefabUtility.IsPartOfPrefabInstance(o)\n    && !(isApply && UnityEditor.EditorUtility.IsPersistent(o))).ToArray();\nif (valid.Length == 0) { Debug.LogWarning(\"No valid objects to apply/revert.\"); return; }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Apply the same validity predicate Unity uses to filter arrays before bulk calls.","Fall back to per-object calls when the batch fails, to surface the specific reason.","Bulk-validate editor selections once at the tool's entry point."],"tags":["prefab","apply-revert","bulk","validation"],"backgroundTag":null,"analyzedSha":"225b0fbdb57cc17d094e8056b71f8314aba56f73","analyzedAt":"2026-08-13T19:07:19.849Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}