feat(manage_editor): add save_prefab_stage action#990
feat(manage_editor): add save_prefab_stage action#990zaferdace wants to merge 1 commit intoCoplayDev:betafrom
Conversation
Adds save_prefab_stage to manage_editor to complete the prefab stage workflow alongside the existing open_prefab_stage and close_prefab_stage. - C#: SavePrefabStage() uses EditorSceneManager.MarkSceneDirty + SaveScene on the prefab stage scene, returns ErrorResponse when no stage is open or save fails - Python: adds save_prefab_stage to action Literal and tool description - Tests: 3 new tests covering forwarding, description, and clean params open_prefab_stage was already merged in CoplayDev#968. This PR only adds save_prefab_stage.
Reviewer's GuideAdds a new manage_editor action save_prefab_stage that saves the currently open Unity prefab stage, wires it through the Python tool surface, and adds tests to verify description, forwarding behavior, and parameter filtering. Sequence diagram for save_prefab_stage tool call workflowsequenceDiagram
actor User
participant Server_manage_editor_tool
participant UnityConnection
participant Unity_ManageEditor
User->>Server_manage_editor_tool: manage_editor(action=save_prefab_stage)
Server_manage_editor_tool->>UnityConnection: async_send_command_with_retry(action=save_prefab_stage)
UnityConnection->>Unity_ManageEditor: HandleCommand(params.action=save_prefab_stage)
Unity_ManageEditor->>Unity_ManageEditor: SavePrefabStage()
Unity_ManageEditor-->>UnityConnection: SuccessResponse | ErrorResponse
UnityConnection-->>Server_manage_editor_tool: response JSON
Server_manage_editor_tool-->>User: tool result (prefabPath, saved | error message)
Class diagram for ManageEditor SavePrefabStage integrationclassDiagram
class ManageEditor {
+static object HandleCommand(JObject params)
-static object OpenPrefabStage(string requestedPath)
-static object SavePrefabStage()
-static object ClosePrefabStage()
}
class ErrorResponse {
+string message
+ErrorResponse(string message)
}
class SuccessResponse {
+string message
+object data
+SuccessResponse(string message, object data)
}
ManageEditor ..> ErrorResponse : returns
ManageEditor ..> SuccessResponse : returns
Flow diagram for SavePrefabStage Unity editor logicflowchart TD
Start([Start SavePrefabStage])
GetStage[Get current prefab stage via PrefabStageUtility.GetCurrentPrefabStage]
NoStage[Return ErrorResponse: not in prefab editing mode]
GetPath[Read prefabPath from prefabStage.assetPath]
MarkDirty["MarkSceneDirty(prefabStage.scene)"]
SaveScene["Call EditorSceneManager.SaveScene(prefabStage.scene)"]
SaveFailed[Return ErrorResponse: save failed]
SaveSuccess[Return SuccessResponse with prefabPath and saved=true]
ExceptionNode[Return ErrorResponse with exception message]
Start --> GetStage
GetStage -->|prefabStage is null| NoStage
GetStage -->|prefabStage exists| GetPath
GetPath --> MarkDirty --> SaveScene
SaveScene -->|saved == false| SaveFailed
SaveScene -->|saved == true| SaveSuccess
Start --> ExceptionCheck{Exception thrown?}
ExceptionCheck -->|yes| ExceptionNode
ExceptionCheck -->|no| GetStage
File-Level Changes
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
📝 WalkthroughWalkthroughThis PR introduces a new Changes
Sequence DiagramsequenceDiagram
participant Client as Client/LLM
participant Server as MCP Server
participant Tool as manage_editor Tool
participant Unity as Unity Editor
participant Editor as EditorSceneManager
Client->>Server: save_prefab_stage action
Server->>Tool: invoke manage_editor(action="save_prefab_stage")
Tool->>Unity: forward save_prefab_stage command
Unity->>Unity: retrieve current PrefabStage
alt PrefabStage exists
Unity->>Unity: mark stage scene as dirty
Unity->>Editor: SaveScene(stage.scene)
Editor-->>Unity: scene saved
Unity-->>Tool: success response {prefabPath, saved: true}
else No PrefabStage active
Unity-->>Tool: error response
end
Tool-->>Server: response
Server-->>Client: result
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
Summary
Complements #968 (
open_prefab_stage) by adding the missingsave_prefab_stageaction tomanage_editor, completing the prefab stage edit workflow.What save_prefab_stage does
PrefabStageUtility.GetCurrentPrefabStage()ErrorResponseimmediately if no stage is open (guides the caller to useopen_prefab_stagefirst)EditorSceneManager.MarkSceneDirtyEditorSceneManager.SaveSceneand checks the return valueErrorResponseif the save failed (read-only file, full disk, etc.)SuccessResponsewithprefabPathandsavedon successFull prefab stage workflow
Changes
SavePrefabStage()method +case "save_prefab_stage"inManageEditor.cssave_prefab_stageadded to actionLiteraland tool description inmanage_editor.pyTest plan
open_prefab_stage, modify an object, callsave_prefab_stage, verify changes persist in the.prefabassetsave_prefab_stagewith no stage open — verifyErrorResponsewith helpful messageclose_prefab_stagestill works unchanged after savingNotes
open_prefab_stagewas merged in #968. This PR only addssave_prefab_stageand is based onbeta.Summary by Sourcery
Add support for saving the currently open Unity prefab stage through the manage_editor tool and wire it through to the Unity editor backend.
New Features:
Enhancements:
Tests:
Summary by CodeRabbit
New Features
Tests