{"record":{"id":"917cb001fa87f233","repo":"Unity-Technologies/UnityCsReference","slug":"input-scene-is-not-valid-could-not-be-found","errorCode":null,"errorMessage":"Input scene is not valid: Could not be found.","messagePattern":"Input scene is not valid: Could not be found\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"Editor/Mono/Prefabs/PrefabUtility.cs","lineNumber":283,"sourceCode":"            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.\");\n            }\n\n            return FindAllInstancesOfPrefab_internal(prefabRoot, scene.handle);\n        }\n\n        public static void MergePrefabInstance(GameObject instanceRoot)\n        {\n            MergePrefabInstance_internal(instanceRoot);\n        }\n\n        public static void RevertPrefabInstance(GameObject instanceRoot, InteractionMode action)\n        {\n            ThrowExceptionIfNotValidPrefabInstanceObject(instanceRoot, false);\n\n            GameObject prefabInstanceRoot = GetOutermostPrefabInstanceRoot(instanceRoot);\n\n            var actionName = \"Revert Prefab Instance\";\n","sourceCodeStart":265,"sourceCodeEnd":301,"githubUrl":"https://github.com/Unity-Technologies/UnityCsReference/blob/225b0fbdb57cc17d094e8056b71f8314aba56f73/Editor/Mono/Prefabs/PrefabUtility.cs#L265-L301","documentation":"Thrown by FindAllInstancesOfPrefab(GameObject, Scene) when the supplied Scene fails scene.IsValid(). Unity scenes are only valid once created or loaded via EditorSceneManager; a default/unloaded/closed scene is invalid. The API needs a concrete loaded scene handle to scope its internal search, so it refuses an invalid one outright.","triggerScenarios":"Calling PrefabUtility.FindAllInstancesOfPrefab(prefab, scene) where scene is the default(Scene) value, a scene that was never opened, a scene returned by a failed EditorSceneManager.OpenScene, or a scene that has since been closed. Also triggered by passing a Scene struct captured before its asynchronous load completed.","commonSituations":"Editor tooling that searches for prefab instances across scenes but operates before the target scene finishes loading; batch processors iterating SceneManager.sceneCount and grabbing a not-yet-loaded scene; scripts reusing a cached Scene handle after the scene was closed.","solutions":["Guard the call with: if (!scene.IsValid()) return; before invoking FindAllInstancesOfPrefab.","Ensure the scene is fully loaded (EditorSceneManager.OpenScene with OpenSceneMode.Additive and check isLoaded) before searching.","If you want to search every loaded scene, call the single-argument overload FindAllInstancesOfPrefab(GameObject prefabRoot) which internally passes SceneHandle.None.","Refresh the Scene reference from SceneManager.GetSceneByPath/ByName right before the call instead of caching it."],"exampleFix":"// before\nvar found = PrefabUtility.FindAllInstancesOfPrefab(prefab, scene);\n\n// after\nif (!scene.IsValid()) return Array.Empty<GameObject>();\nvar found = PrefabUtility.FindAllInstancesOfPrefab(prefab, scene);","handlingStrategy":"validation","validationCode":"if (scene == null || !scene.IsValid())\n{\n    Debug.LogWarning(\"Scene is not valid; skipping prefab instance search.\");\n    return Array.Empty<GameObject>();\n}\nreturn PrefabUtility.FindAllInstancesOfPrefab(prefabRoot, scene);","typeGuard":"static bool IsSceneUsable(Scene scene) => scene.IsValid() && scene.isLoaded && scene.rootCount >= 0;","tryCatchPattern":null,"preventionTips":["Always call scene.IsValid() before any Scene-scoped PrefabUtility API.","Refresh Scene references from SceneManager/EditorSceneManager immediately before use, do not cache across scene lifetimes.","Prefer the single-argument FindAllInstancesOfPrefab overload when you want all loaded scenes searched."],"tags":["prefab","scene","validation","editor"],"backgroundTag":null,"analyzedSha":"225b0fbdb57cc17d094e8056b71f8314aba56f73","analyzedAt":"2026-08-13T19:07:19.849Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}