Skip to content

feat(prefabs): add refresh flag to save_prefab_stage to skip AssetDatabase.Refresh()#1123

Open
sssooonnnggg wants to merge 1 commit into
CoplayDev:betafrom
sssooonnnggg:beta
Open

feat(prefabs): add refresh flag to save_prefab_stage to skip AssetDatabase.Refresh()#1123
sssooonnnggg wants to merge 1 commit into
CoplayDev:betafrom
sssooonnnggg:beta

Conversation

@sssooonnnggg
Copy link
Copy Markdown
Contributor

@sssooonnnggg sssooonnnggg commented May 13, 2026

Allows callers to opt out of the trailing SaveAssets()+Refresh() (often ~1s on large projects) and trigger refresh_unity themselves when needed.

Summary by CodeRabbit

  • New Features

    • Save and close prefab operations now accept an optional refresh flag to control whether the editor runs the post-save refresh step.
    • Close operation respects the refresh choice when saving before closing.
  • Documentation

    • Usage note and performance tip added: opting out of automatic refresh avoids the trailing import delay; manually trigger refresh when needed.

Review Change Stack

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 13, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: f5637c4b-c1e7-4900-b70c-ee0df2d10efe

📥 Commits

Reviewing files that changed from the base of the PR and between 20a05f9 and c418fe4.

📒 Files selected for processing (2)
  • MCPForUnity/Editor/Tools/Prefabs/ManagePrefabs.cs
  • Server/src/services/tools/manage_prefabs.py
🚧 Files skipped from review as they are similar to previous changes (2)
  • MCPForUnity/Editor/Tools/Prefabs/ManagePrefabs.cs
  • Server/src/services/tools/manage_prefabs.py

📝 Walkthrough

Walkthrough

Adds an optional refresh boolean to prefab-stage save/close flows: the C# handler forwards it into SavePrefabStage/ClosePrefabStage → TrySavePrefabStage, where AssetDatabase.Refresh() runs only if refresh is true; Python tool accepts and forwards the refresh flag.

Changes

Prefab-stage save refresh control

Layer / File(s) Summary
C# handler → save/close → conditional refresh
MCPForUnity/Editor/Tools/Prefabs/ManagePrefabs.cs
HandleCommand reads optional refresh for save_prefab_stage and close_prefab_stage and forwards it to SavePrefabStage(refresh) / ClosePrefabStage(saveBeforeClose, refresh). SavePrefabStage(bool refreshAfterSave = true) forwards the flag to TrySavePrefabStage; TrySavePrefabStage always calls AssetDatabase.SaveAssets() but only calls AssetDatabase.Refresh() when refreshAfterSave is true.
Python tool interface and documentation
Server/src/services/tools/manage_prefabs.py
Tool docstring extended with usage and a refresh=false performance tip. manage_prefabs signature adds optional refresh: bool; the implementation coerces it to a boolean and includes params["refresh"] when present.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • CoplayDev/unity-mcp#1013: Modifies manage_prefabs prefab-stage workflow; related to routing/open/save/close changes in ManagePrefabs.

Poem

🐰 In the editor's quiet glade I hop,
A tiny flag lets refresh stop—
SaveAssets hums while imports wait,
Batch work sleeps, performance great. 🥕✨

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The pull request description is incomplete. While it provides a brief overview, it lacks required sections like Type of Change, detailed Changes Made, Testing, and Documentation Updates acknowledgment. Complete the PR description by adding: Type of Change (New feature), detailed Changes Made section, Testing/Screenshots section, and Documentation Updates checklist with confirmation of updates.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: adding a refresh flag to save_prefab_stage to control AssetDatabase.Refresh() execution.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov-commenter
Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

❌ Patch coverage is 66.66667% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
Server/src/services/tools/manage_prefabs.py 66.66% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
Server/src/services/tools/manage_prefabs.py (1)

24-48: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Add explicit tool group in the decorator.

This tool decorator is missing the required group argument. Please set it explicitly (for example, group="core" if that’s intended) to keep visibility behavior deterministic.

Proposed fix
 `@mcp_for_unity_tool`(
     description=(
         "Manages Unity Prefab assets. "
         "Actions: get_info, get_hierarchy, create_from_gameobject, modify_contents, open_prefab_stage, save_prefab_stage, close_prefab_stage. "
@@
     annotations=ToolAnnotations(
         title="Manage Prefabs",
         destructiveHint=True,
     ),
+    group="core",
 )

As per coding guidelines: Server/src/services/tools/*.py: “must use the @mcp_for_unity_tool decorator with a description and group parameter” and “Use the group parameter in @mcp_for_unity_tool to control tool visibility...”.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@Server/src/services/tools/manage_prefabs.py` around lines 24 - 48, The
`@mcp_for_unity_tool` decorator on the Manage Prefabs tool is missing the required
group argument; update the decorator call (the one annotating the manage_prefabs
tool) to include an explicit group value (e.g., group="core") alongside the
existing description and annotations so the tool's visibility is deterministic;
ensure you add the group parameter to the `@mcp_for_unity_tool`(...) invocation
that wraps this module's managed-prefab functions.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@Server/src/services/tools/manage_prefabs.py`:
- Around line 24-48: The `@mcp_for_unity_tool` decorator on the Manage Prefabs
tool is missing the required group argument; update the decorator call (the one
annotating the manage_prefabs tool) to include an explicit group value (e.g.,
group="core") alongside the existing description and annotations so the tool's
visibility is deterministic; ensure you add the group parameter to the
`@mcp_for_unity_tool`(...) invocation that wraps this module's managed-prefab
functions.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 5cc54f6c-8a05-49fc-951f-378c3ff56332

📥 Commits

Reviewing files that changed from the base of the PR and between a2a5edf and 20a05f9.

📒 Files selected for processing (2)
  • MCPForUnity/Editor/Tools/Prefabs/ManagePrefabs.cs
  • Server/src/services/tools/manage_prefabs.py

…abase.Refresh()

Allows callers to opt out of the trailing AssetDatabase.Refresh() (often ~1s on
large projects) and trigger refresh_unity themselves when needed. SaveAssets()
still runs unconditionally so any dirty assets are flushed before returning.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants