-
Notifications
You must be signed in to change notification settings - Fork 628
Description
Unity MCP Feature Request: Prefab Creation from Inactive GameObjects
Summary
The manage_prefabs tool with action: "create_from_gameobject" cannot locate GameObjects that have been set to inactive (SetActive(false)), even when those objects exist in the scene and can be found by other tools.
Environment
- Unity MCP (version unknown - whatever's current as of Jan 2025)
- Unity 6000.13f1
- Scene: MainMenu.unity
Steps to Reproduce
1. Create a GameObject successfully:
{
"tool": "manage_gameobject",
"params": {
"action": "create",
"name": "CoreStatsPanel",
"parent": "MainMenuCanvas (1)",
"components_to_add": ["UnityEngine.UI.Image", "XStellar.UI.Controllers.CoreStatsController"]
}
}
✅ Result: GameObject created with instanceID -70128
2. Set the GameObject to inactive:
{
"tool": "manage_gameobject",
"params": {
"action": "modify",
"name": "CoreStatsPanel",
"set_active": false
}
}
✅ Result: GameObject set to activeSelf: false
3. Verify the object still exists (this works):
{
"tool": "manage_gameobject",
"params": {
"action": "find",
"search_method": "by_name",
"search_term": "CoreStatsPanel",
"search_inactive": true
}
}
✅ Result: Found 1 GameObject with correct instanceID -70128, shows activeSelf: false
4. Attempt to create prefab (this fails):
{
"tool": "manage_prefabs",
"params": {
"action": "create_from_gameobject",
"target": "CoreStatsPanel",
"prefab_path": "Assets/Prefabs/UI/CoreStats/CoreStatsPanel.prefab",
"allow_overwrite": true
}
}
❌ Result:
{
"success": false,
"code": "GameObject 'CoreStatsPanel' not found in the active scene.",
"error": "GameObject 'CoreStatsPanel' not found in the active scene."
}
Workarounds Attempted (All Failed)
| Attempt | Parameter Used | Result |
|---|---|---|
| Search by path | target: "MainMenuCanvas (1)/CoreStatsPanel" | Same error |
| Search inactive flag | search_inactive: true | Parameter not recognized/ignored |
| Use instance ID | target: "-70128" | Same error |
| Re-activate then create | set_active: true on modify | Modify command also couldn't find inactive object |
Root Cause Analysis
The manage_prefabs tool appears to use a lookup method that only searches active GameObjects (likely GameObject.Find() or similar), whereas manage_gameobject with action: "find" has the search_inactive parameter that uses FindObjectsByType<T>(FindObjectsInactive.Include).
The prefab creation tool should support:
- A
search_inactiveparameter like the find action has - Lookup by instanceID (which is unambiguous)
- Or ideally, accepting the result object from a prior
findcall
Impact
This prevents a common workflow:
- Build complex UI hierarchy in scene
- Set panel to inactive (standard practice for UI panels)
- Save as prefab
- Delete scene instance
Users must either:
- Keep all objects active (clutters scene view, may cause runtime issues)
- Use a separate Editor script approach (defeats purpose of MCP)
- Manually create prefabs in Unity Editor
Suggested Fix
Add search_inactive parameter to manage_prefabs tool:
{
"tool": "manage_prefabs",
"params": {
"action": "create_from_gameobject",
"target": "CoreStatsPanel",
"search_inactive": true, // NEW PARAMETER
"prefab_path": "Assets/Prefabs/UI/CoreStats/CoreStatsPanel.prefab"
}
}
Or support instanceID targeting:
{
"tool": "manage_prefabs",
"params": {
"action": "create_from_gameobject",
"target_instance_id": -70128, // Direct reference
"prefab_path": "Assets/Prefabs/UI/CoreStats/CoreStatsPanel.prefab"
}
}
Additional Context
The manage_gameobject tool with action: "modify"
has the same limitation - it cannot modify inactive GameObjects even
when you know their exact path or instanceID. This suggests the
underlying GameObject lookup utility used across multiple tools needs
the inactive search capability.