Skip to content

Feature: Add Prefab Editor Inspection & Modification Support #97

Closed

Description

@KamilDev

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

  1. 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
  2. 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
  3. 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
  4. 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:

  1. Detect the prefab is open for editing
  2. List its full hierarchy
  3. Find a TextMeshProUGUI component displaying "10"
  4. Rename its GameObject to a more descriptive name like "CountdownText"

Activity

  1. cloudosed commented on Apr 15, 2025

    @cloudosed

    It's there any C# function inside unity engine that can achieve your needs?

  2. msanatan commented on Aug 11, 2025

    @msanatan
    Member

    Awesome use case @KamilDev

  3. added
    enhancement
    on Aug 11, 2025
  4. msanatan commented on Sep 26, 2025

    @msanatan
    Member

    We added some more support for prefabs in v4.0.0, but changes in #287 should help

  5. msanatan commented on Jan 8, 2026

    @msanatan
    Member

    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

  6. cyanxwh commented on Jan 12, 2026

    @cyanxwh
    Contributor

    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:

    1. open_stage successfully opens the prefab.
    2. manage_components (action: "add") reports success.
    3. save_open_stage and close_stage report success.
    4. 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.

  7. whatevertogo commented on Jan 23, 2026

    @whatevertogo
    Contributor

    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:  实际行为:

    1. open_stage successfully opens the prefab.open_stage 成功地打开了预制件。
    2. manage_components (action: "add") reports success.manage_components(操作:“添加”)报告成功。
    3. save_open_stage and close_stage report success.save_open_stage 和 close_stage 报告成功。
    4. 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:

    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  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

  8. dsarno commented on Jan 26, 2026

    @dsarno
    Collaborator

    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.

  9. msanatan commented on Jan 26, 2026

    @msanatan
    Member

    @dsarno the legend

  10. dsarno commented on Jan 26, 2026

    @dsarno
    Collaborator

    Thanks, and big shoutout to @whatevertogo for getting the prefab fixes going!

  11. whatevertogo commented on Jan 26, 2026

    @whatevertogo
    Contributor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions