Feature: Add Prefab Editor Inspection & Modification Support
I'm trying to work with a modal window prefab, but it seems the MCP doesn't have sufficient tools for working with opened prefabs (not in scene view).
Specifically, I double-click a prefab asset in the project file browser, which opens the prefab in a special isolated view -- that's what I want to work with using the MCP.
My ideal workflow would be:
- Inside the prefab, I create the UI I want myself.
- The AI can access the properties of objects (such as text content) to intelligently rename objects that have a generic default name.
- The AI can hook up these objects into the root parent object modal script serialized fields accordingly.
I tried a basic test of trying to get the AI to access the actively open prefab, rename a generically named text object with the text value "10" to a more descriptive "countdown text" name.
It couldn't access the opened prefab, so I gave the path manually, but it still seems to not be able to access the hierarchy or enough information to do anything useful.
I had the AI generate an issue request, if you find it useful:
Issue Description
The current Unity MCP tools lack functionality to work with prefabs that are actively being edited in the prefab editor. This limitation prevents basic prefab inspection and modification operations that would be valuable for AI-assisted workflows.
Requested Features
-
Access to actively selected/open prefab
- Add ability to detect and reference the prefab currently being edited in the prefab editor
- Return prefab path, type, and basic metadata
-
Prefab hierarchy inspection
- List complete hierarchy of GameObjects within the prefab
- Include component types, names, and relevant properties for each GameObject
- Support filtering by component type or property value
-
Text content searching
- Add capability to find UI elements with specific text content
- Support exact matches and pattern-based searches
- Return hierarchy path to matching elements
-
GameObject renaming in prefab context
- Allow renaming of GameObjects within a prefab hierarchy
- Support renaming by direct GameObject reference
Use Case Example
When editing a UI prefab, an assistant should be able to:
- Detect the prefab is open for editing
- List its full hierarchy
- Find a TextMeshProUGUI component displaying "10"
- Rename its GameObject to a more descriptive name like "CountdownText"
It's there any C# function inside unity engine that can achieve your needs?
Awesome use case @KamilDev
We added some more support for prefabs in v4.0.0, but changes in #287 should help
Modifying prefabs has been improved a lot since you post this issue, but there's probably one last change to make this workflow fully complete. I'm thinking a new resource to list the prefab hierarchy. Once there's visibility, this entire flow will work
Hi there,
I encountered an issue where UnityMCP fails to modify existing standalone Prefab assets when using the open_stage / save_open_stage workflow. Claude Code attempted to add a component, but the changes were lost after closing the stage.
Actual Behavior:
- open_stage successfully opens the prefab.
- manage_components (action: "add") reports success.
- save_open_stage and close_stage report success.
- However, a subsequent get_components call shows the component was never actually saved to the .prefab asset.
Workaround found by Claude: Claude eventually had to resort to deleting and recreating the entire prefab from a new GameObject to "apply" the changes, which isn't ideal for existing references.
Full Log:
Click to expand full terminal output
❯ create a Prefab aseet file and add a random component using UnityMCP
● I'll first verify the active Unity instance, then create a prefab and add a component to it.
● readMcpResource(Read resource "mcpforunity://instances" from server "UnityMCP")
⎿ {
"contents": [
{
… +10 lines (ctrl+o to expand)
● Good, the Unity instance is active. Now I'll create a GameObject, add a random component (I'll use Rigidbody), and save it as a prefab.
● UnityMCP - Manage GameObject (MCP)(action: "create", name: "TestPrefabObject",
primitive_type: "Cube", components_to_add:
["Rigidbody"], save_as_prefab: true, prefab_folder:
"Assets/Prefabs")
⎿ {
"success": true,
"message": "GameObject 'TestPrefabObject' created and saved as prefab to
'As
… +62 lines (ctrl+o to expand)
● Done! I created a prefab asset with a Rigidbody component:
- Prefab path: Assets/Prefabs/TestPrefabObject.prefab
- Base type: Cube primitive
- Components:
- Transform
- MeshFilter
- BoxCollider
- MeshRenderer
- Rigidbody (added component)
The prefab is now available in your project's Assets/Prefabs folder.
❯ add another random component to this prefab
● UnityMCP - Manage Prefabs (MCP)(action: "open_stage", prefab_path:
"Assets/Prefabs/TestPrefabObject.prefab")
⎿ {
"success": true,
"message": "Opened prefab stage for
'Assets/Prefabs/TestPrefabObject.prefab'
… +9 lines (ctrl+o to expand)
● UnityMCP - manage_components (MCP)(action: "add", target: "TestPrefabObject",
component_type: "AudioSource")
⎿ {
"success": true,
"message": "Component 'AudioSource' added to 'TestPrefabObject'.",
… +6 lines (ctrl+o to expand)
● UnityMCP - Manage Prefabs (MCP)(action: "save_open_stage")
⎿ {
"success": true,
"message": "Saved prefab stage for
'Assets/Prefabs/TestPrefabObject.prefab'.
… +9 lines (ctrl+o to expand)
● UnityMCP - Manage Prefabs (MCP)(action: "close_stage")
⎿ {
"success": true,
"message": "Closed prefab stage for ''.",
… +2 lines (ctrl+o to expand)
● Done! I added an AudioSource component to the prefab.
TestPrefabObject.prefab now has:
- Transform
- MeshFilter
- BoxCollider
- MeshRenderer
- Rigidbody
- AudioSource (newly added)
✻ Cogitated for 1m 27s
❯ I can't see a AudioSource on it, validate again
● Let me check the prefab's current components.
● UnityMCP - Manage Asset (MCP)(action: "get_components", path:
"Assets/Prefabs/TestPrefabObject.prefab")
⎿ {
"success": true,
"message": "Found 5 component(s) on asset
'Assets/Prefabs/TestPrefabObject.p
… +24 lines (ctrl+o to expand)
● You're right - the AudioSource wasn't saved to the prefab. Let me add it again properly.
● UnityMCP - Manage Prefabs (MCP)(action: "open_stage", prefab_path:
"Assets/Prefabs/TestPrefabObject.prefab")
⎿ {
"success": true,
"message": "Opened prefab stage for
'Assets/Prefabs/TestPrefabObject.prefab'
… +9 lines (ctrl+o to expand)
● UnityMCP - find_gameobjects (MCP)(search_term: "TestPrefabObject", search_method:
"by_name")
⎿ {
"success": true,
"message": "Found GameObjects",
… +12 lines (ctrl+o to expand)
● UnityMCP - manage_components (MCP)(action: "add", target: -37268, search_method:
"by_id", component_type: "AudioSource")
⎿ {
"success": true,
"message": "Component 'AudioSource' added to 'TestPrefabObject'.",
… +6 lines (ctrl+o to expand)
● UnityMCP - Manage Prefabs (MCP)(action: "save_open_stage")
⎿ {
"success": true,
"message": "Saved prefab stage for
'Assets/Prefabs/TestPrefabObject.prefab'.
… +9 lines (ctrl+o to expand)
● UnityMCP - Manage Prefabs (MCP)(action: "close_stage")
⎿ {
"success": true,
"message": "Closed prefab stage for ''.",
… +2 lines (ctrl+o to expand)
● UnityMCP - Manage Asset (MCP)(action: "get_components", path:
"Assets/Prefabs/TestPrefabObject.prefab")
⎿ {
"success": true,
"message": "Found 5 component(s) on asset
'Assets/Prefabs/TestPrefabObject.p
… +24 lines (ctrl+o to expand)
● The AudioSource still isn't persisting. Let me try a different approach - instantiate the prefab, add the component, and overwrite the prefab.
● UnityMCP - Manage GameObject (MCP)(action: "create", name: "TempPrefabInstance",
prefab_path:
"Assets/Prefabs/TestPrefabObject.prefab")
⎿ {
"success": true,
"message": "Prefab 'Assets/Prefabs/TestPrefabObject.prefab' instantiated
suc
… +63 lines (ctrl+o to expand)
● UnityMCP - manage_components (MCP)(action: "add", target: -47794, search_method:
"by_id", component_type: "AudioSource")
⎿ {
"success": true,
"message": "Component 'AudioSource' added to 'TempPrefabInstance'.",
… +6 lines (ctrl+o to expand)
● UnityMCP - Manage Prefabs (MCP)(action: "create_from_gameobject", target: "-47794",
prefab_path: "Assets/Prefabs/TestPrefabObject.prefab",
allow_overwrite: true)
⎿ {
"success": false,
"code": "GameObject '-47794' not found in the active scene.",
… +2 lines (ctrl+o to expand)
● UnityMCP - Manage Prefabs (MCP)(action: "create_from_gameobject", target:
"TempPrefabInstance", prefab_path:
"Assets/Prefabs/TestPrefabObject.prefab",
allow_overwrite: true)
⎿ {
"success": false,
"code": "GameObject 'TempPrefabInstance' is already linked to an existing
pr
… +4 lines (ctrl+o to expand)
● Let me try a different approach - create a fresh GameObject with the component and overwrite the prefab.
● UnityMCP - Manage GameObject (MCP)(action: "delete", target: "TempPrefabInstance")
⎿ {
"success": true,
"message": "GameObject 'TempPrefabInstance' deleted successfully.",
… +7 lines (ctrl+o to expand)
● UnityMCP - Manage GameObject (MCP)(action: "create", name: "TestPrefabObject",
primitive_type: "Cube", components_to_add:
["Rigidbody","AudioSource"], save_as_prefab: true,
prefab_folder: "Assets/Prefabs")
⎿ {
"success": true,
"message": "GameObject 'TestPrefabObject' created and saved as prefab to
'As
… +63 lines (ctrl+o to expand)
● Now let me verify the prefab has the AudioSource.
● UnityMCP - Manage Asset (MCP)(action: "get_components", path:
"Assets/Prefabs/TestPrefabObject.prefab")
⎿ {
"success": true,
"message": "Found 6 component(s) on asset
'Assets/Prefabs/TestPrefabObject.p
… +28 lines (ctrl+o to expand)
● Confirmed! The prefab now has 6 components including the AudioSource:
1. Transform
2. MeshFilter
3. BoxCollider
4. MeshRenderer
5. Rigidbody
6. AudioSource ✓
The prefab stage approach wasn't persisting changes properly, so I recreated the prefab with both components. You should now see the AudioSource on Assets/Prefabs/TestPrefabObject.prefab.
Environment:
UnityMCP version: 9.0.3
Unity version: 6000.0.41f
Claude Code version: 2.1.5
Model: Claude Opus 4.5
It seems like save_open_stage might not be correctly triggering the internal Unity PrefabUtility save or asset database refresh.
I already fix that, please wait for the next version
Hi there, 你好,
I encountered an issue where UnityMCP fails to modify existing standalone Prefab assets when using the open_stage / save_open_stage workflow. Claude Code attempted to add a component, but the changes were lost after closing the stage.我遇到一个问题,当使用 open_stage / save_open_stage 工作流时,UnityMCP 无法修改现有的独立预设资产。Claude Code 尝试添加一个组件,但关闭阶段后更改丢失了。
Actual Behavior: 实际行为:
- open_stage successfully opens the prefab.open_stage 成功地打开了预制件。
- manage_components (action: "add") reports success.manage_components(操作:“添加”)报告成功。
- save_open_stage and close_stage report success.save_open_stage 和 close_stage 报告成功。
- However, a subsequent get_components call shows the component was never actually saved to the .prefab asset.然而,随后的 get_components 调用显示该组件从未实际保存到 .prefab 资源中。
Workaround found by Claude: Claude eventually had to resort to deleting and recreating the entire prefab from a new GameObject to "apply" the changes, which isn't ideal for existing references.克劳德找到了一个解决方案:克劳德最终不得不从一个新 GameObject 中删除和重新创建整个预制体来“应用”更改,这对现有的引用来说并不理想。
Full Log: 完整日志:
Click to expand full terminal output 点击展开终端输出 ❯ create a Prefab aseet file and add a random component using UnityMCP
● I'll first verify the active Unity instance, then create a prefab and add a component to it.
● readMcpResource(Read resource "mcpforunity://instances" from server "UnityMCP") ⎿ { "contents": [ { … +10 lines (ctrl+o to expand)
● Good, the Unity instance is active. Now I'll create a GameObject, add a random component (I'll use Rigidbody), and save it as a prefab.
● UnityMCP - Manage GameObject (MCP)(action: "create", name: "TestPrefabObject", primitive_type: "Cube", components_to_add: ["Rigidbody"], save_as_prefab: true, prefab_folder: "Assets/Prefabs") ⎿ { "success": true, "message": "GameObject 'TestPrefabObject' created and saved as prefab to 'As … +62 lines (ctrl+o to expand)
● Done! I created a prefab asset with a Rigidbody component:
- Prefab path: Assets/Prefabs/TestPrefabObject.prefab
- Base type: Cube primitive
- Components:
- Transform
- MeshFilter
- BoxCollider
- MeshRenderer
- Rigidbody (added component)
The prefab is now available in your project's Assets/Prefabs folder.
❯ add another random component to this prefab
● UnityMCP - Manage Prefabs (MCP)(action: "open_stage", prefab_path: "Assets/Prefabs/TestPrefabObject.prefab") ⎿ { "success": true, "message": "Opened prefab stage for 'Assets/Prefabs/TestPrefabObject.prefab' … +9 lines (ctrl+o to expand)
● UnityMCP - manage_components (MCP)(action: "add", target: "TestPrefabObject", component_type: "AudioSource") ⎿ { "success": true, "message": "Component 'AudioSource' added to 'TestPrefabObject'.", … +6 lines (ctrl+o to expand)
● UnityMCP - Manage Prefabs (MCP)(action: "save_open_stage") ⎿ { "success": true, "message": "Saved prefab stage for 'Assets/Prefabs/TestPrefabObject.prefab'. … +9 lines (ctrl+o to expand)
● UnityMCP - Manage Prefabs (MCP)(action: "close_stage") ⎿ { "success": true, "message": "Closed prefab stage for ''.", … +2 lines (ctrl+o to expand)
● Done! I added an AudioSource component to the prefab.
TestPrefabObject.prefab now has:
- Transform
- MeshFilter
- BoxCollider
- MeshRenderer
- Rigidbody
- AudioSource (newly added)
✻ Cogitated for 1m 27s
❯ I can't see a AudioSource on it, validate again
● Let me check the prefab's current components.
● UnityMCP - Manage Asset (MCP)(action: "get_components", path: "Assets/Prefabs/TestPrefabObject.prefab") ⎿ { "success": true, "message": "Found 5 component(s) on asset 'Assets/Prefabs/TestPrefabObject.p … +24 lines (ctrl+o to expand)
● You're right - the AudioSource wasn't saved to the prefab. Let me add it again properly.
● UnityMCP - Manage Prefabs (MCP)(action: "open_stage", prefab_path: "Assets/Prefabs/TestPrefabObject.prefab") ⎿ { "success": true, "message": "Opened prefab stage for 'Assets/Prefabs/TestPrefabObject.prefab' … +9 lines (ctrl+o to expand)
● UnityMCP - find_gameobjects (MCP)(search_term: "TestPrefabObject", search_method: "by_name") ⎿ { "success": true, "message": "Found GameObjects", … +12 lines (ctrl+o to expand)
● UnityMCP - manage_components (MCP)(action: "add", target: -37268, search_method: "by_id", component_type: "AudioSource") ⎿ { "success": true, "message": "Component 'AudioSource' added to 'TestPrefabObject'.", … +6 lines (ctrl+o to expand)
● UnityMCP - Manage Prefabs (MCP)(action: "save_open_stage") ⎿ { "success": true, "message": "Saved prefab stage for 'Assets/Prefabs/TestPrefabObject.prefab'. … +9 lines (ctrl+o to expand)
● UnityMCP - Manage Prefabs (MCP)(action: "close_stage") ⎿ { "success": true, "message": "Closed prefab stage for ''.", … +2 lines (ctrl+o to expand)
● UnityMCP - Manage Asset (MCP)(action: "get_components", path: "Assets/Prefabs/TestPrefabObject.prefab") ⎿ { "success": true, "message": "Found 5 component(s) on asset 'Assets/Prefabs/TestPrefabObject.p … +24 lines (ctrl+o to expand)
● The AudioSource still isn't persisting. Let me try a different approach - instantiate the prefab, add the component, and overwrite the prefab.
● UnityMCP - Manage GameObject (MCP)(action: "create", name: "TempPrefabInstance", prefab_path: "Assets/Prefabs/TestPrefabObject.prefab") ⎿ { "success": true, "message": "Prefab 'Assets/Prefabs/TestPrefabObject.prefab' instantiated suc … +63 lines (ctrl+o to expand)
● UnityMCP - manage_components (MCP)(action: "add", target: -47794, search_method: "by_id", component_type: "AudioSource") ⎿ { "success": true, "message": "Component 'AudioSource' added to 'TempPrefabInstance'.", … +6 lines (ctrl+o to expand)
● UnityMCP - Manage Prefabs (MCP)(action: "create_from_gameobject", target: "-47794", prefab_path: "Assets/Prefabs/TestPrefabObject.prefab", allow_overwrite: true) ⎿ { "success": false, "code": "GameObject '-47794' not found in the active scene.", … +2 lines (ctrl+o to expand)
● UnityMCP - Manage Prefabs (MCP)(action: "create_from_gameobject", target: "TempPrefabInstance", prefab_path: "Assets/Prefabs/TestPrefabObject.prefab", allow_overwrite: true) ⎿ { "success": false, "code": "GameObject 'TempPrefabInstance' is already linked to an existing pr … +4 lines (ctrl+o to expand)
● Let me try a different approach - create a fresh GameObject with the component and overwrite the prefab.
● UnityMCP - Manage GameObject (MCP)(action: "delete", target: "TempPrefabInstance") ⎿ { "success": true, "message": "GameObject 'TempPrefabInstance' deleted successfully.", … +7 lines (ctrl+o to expand)
● UnityMCP - Manage GameObject (MCP)(action: "create", name: "TestPrefabObject", primitive_type: "Cube", components_to_add: ["Rigidbody","AudioSource"], save_as_prefab: true, prefab_folder: "Assets/Prefabs") ⎿ { "success": true, "message": "GameObject 'TestPrefabObject' created and saved as prefab to 'As … +63 lines (ctrl+o to expand)
● Now let me verify the prefab has the AudioSource.
● UnityMCP - Manage Asset (MCP)(action: "get_components", path: "Assets/Prefabs/TestPrefabObject.prefab") ⎿ { "success": true, "message": "Found 6 component(s) on asset 'Assets/Prefabs/TestPrefabObject.p … +28 lines (ctrl+o to expand)
● Confirmed! The prefab now has 6 components including the AudioSource:
- Transform
- MeshFilter
- BoxCollider
- MeshRenderer
- Rigidbody
- AudioSource ✓
The prefab stage approach wasn't persisting changes properly, so I recreated the prefab with both components. You should now see the AudioSource on Assets/Prefabs/TestPrefabObject.prefab. Environment: 環境:
UnityMCP version: 9.0.3 UnityMCP 版本:9.0.3
Unity version: 6000.0.41fUnity 版本:6000.0.41f
Claude Code version: 2.1.5克劳德·科德版本:2.1.5
Model: Claude Opus 4.5型号:Claude Opus 4.5
It seems like save_open_stage might not be correctly triggering the internal Unity PrefabUtility save or asset database refresh.似乎 save_open_stage 无法正确触发内部 Unity PrefabUtility 保存或资产数据库刷新。
I already fix that, please wait for the next version
Everything in here should now be taken care of, including @msanatan 's suggestion to add read resources to prefab mode.
See #611 and #627 . Thanks all, always feels good to close down an old issue.
@dsarno the legend
Thanks, and big shoutout to @whatevertogo for getting the prefab fixes going!
Thanks! Love the project, happy to make it better.