-
Notifications
You must be signed in to change notification settings - Fork 628
Description
When a prefab is opened in Unity's Prefab Stage (isolation editing mode), the find_gameobjects tool cannot find any GameObjects within the prefab. All searches return empty results.
Root Cause
In GameObjectLookup.cs:250-264, the GetAllSceneObjects method uses SceneManager.GetActiveScene() to get the scene's root objects:
public static IEnumerable GetAllSceneObjects(bool includeInactive)
{
var scene = SceneManager.GetActiveScene(); // ← Problem here
if (!scene.IsValid())
yield break;
var rootObjects = scene.GetRootGameObjects();
// ...
}
When in Prefab Stage mode, SceneManager.GetActiveScene() returns the main scene, not the prefab editing scene. The prefab's contents exist in a separate preview scene accessible via PrefabStageUtility.GetCurrentPrefabStage().scene.
Additionally, SearchByPath (line 148) uses GameObject.Find(path) which also cannot find objects in the Prefab Stage.
Suggested Fix
Modify GetAllSceneObjects to check for Prefab Stage first:
public static IEnumerable GetAllSceneObjects(bool includeInactive)
{
// Check Prefab Stage first
var prefabStage = UnityEditor.SceneManagement.PrefabStageUtility.GetCurrentPrefabStage();
if (prefabStage != null)
{
var prefabRoot = prefabStage.prefabContentsRoot;
if (prefabRoot != null)
{
foreach (var go in GetObjectAndDescendants(prefabRoot, includeInactive))
{
yield return go;
}
}
yield break;
}
// Normal scene mode
var scene = SceneManager.GetActiveScene();
if (!scene.IsValid())
yield break;
var rootObjects = scene.GetRootGameObjects();
foreach (var root in rootObjects)
{
foreach (var go in GetObjectAndDescendants(root, includeInactive))
{
yield return go;
}
}
}
Environment
- Unity 2022.3.x
- unity-mcp latest version