Unity-Technologies/UnityCsReference · error · ArgumentException

Input scene is not valid: Could not be found.

Error message

Input scene is not valid: Could not be found.

What it means

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.

Source

Thrown at Editor/Mono/Prefabs/PrefabUtility.cs:283

            throw new ArgumentException("Cannot apply or revert on any of the objects. Attempt with individual objects for details.", nameof(prefabInstanceObjects));
        }

        static void ThrowExceptionIfInstanceIsPersistent(Object prefabInstanceObject)
        {
            if (EditorUtility.IsPersistent(prefabInstanceObject))
                throw new ArgumentException("Calling apply methods on an instance which is part of a Prefab Asset is not supported.", nameof(prefabInstanceObject));
        }

        public static GameObject[] FindAllInstancesOfPrefab(GameObject prefabRoot)
        {
            return FindAllInstancesOfPrefab_internal(prefabRoot, SceneHandle.None);
        }

        public static GameObject[] FindAllInstancesOfPrefab(GameObject prefabRoot, Scene scene)
        {
            if (!scene.IsValid())
            {
                throw new ArgumentException("Input scene is not valid: Could not be found.");
            }

            return FindAllInstancesOfPrefab_internal(prefabRoot, scene.handle);
        }

        public static void MergePrefabInstance(GameObject instanceRoot)
        {
            MergePrefabInstance_internal(instanceRoot);
        }

        public static void RevertPrefabInstance(GameObject instanceRoot, InteractionMode action)
        {
            ThrowExceptionIfNotValidPrefabInstanceObject(instanceRoot, false);

            GameObject prefabInstanceRoot = GetOutermostPrefabInstanceRoot(instanceRoot);

            var actionName = "Revert Prefab Instance";

View on GitHub (pinned to 225b0fbdb5)

Solutions

  1. Guard the call with: if (!scene.IsValid()) return; before invoking FindAllInstancesOfPrefab.
  2. Ensure the scene is fully loaded (EditorSceneManager.OpenScene with OpenSceneMode.Additive and check isLoaded) before searching.
  3. If you want to search every loaded scene, call the single-argument overload FindAllInstancesOfPrefab(GameObject prefabRoot) which internally passes SceneHandle.None.
  4. Refresh the Scene reference from SceneManager.GetSceneByPath/ByName right before the call instead of caching it.

Example fix

// before
var found = PrefabUtility.FindAllInstancesOfPrefab(prefab, scene);

// after
if (!scene.IsValid()) return Array.Empty<GameObject>();
var found = PrefabUtility.FindAllInstancesOfPrefab(prefab, scene);
Defensive patterns

Strategy: validation

Validate before calling

if (scene == null || !scene.IsValid())
{
    Debug.LogWarning("Scene is not valid; skipping prefab instance search.");
    return Array.Empty<GameObject>();
}
return PrefabUtility.FindAllInstancesOfPrefab(prefabRoot, scene);

Type guard

static bool IsSceneUsable(Scene scene) => scene.IsValid() && scene.isLoaded && scene.rootCount >= 0;

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of Unity-Technologies/UnityCsReference@225b0fbdb5 (2026-08-13). Data as JSON: /api/errors/917cb001fa87f233. Report an issue: GitHub.