fix: save prefab stage edits using the correct prefab-stage workflow#1056
fix: save prefab stage edits using the correct prefab-stage workflow#1056jacklaplante wants to merge 1 commit intoCoplayDev:betafrom
Conversation
|
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 (2)
📝 WalkthroughWalkthroughReplaced prefab-stage scene-save logic with prefab-asset-save workflow by introducing a private helper method Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 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 |
Reviewer's GuideUnifies and fixes prefab-stage saving by introducing a shared helper that persists changes from the prefab contents root back to the prefab asset path, and adds focused EditMode tests to verify explicit save and save-before-close behavior. Sequence diagram for explicit save_prefab_stage command using TrySavePrefabStagesequenceDiagram
actor User
participant ManagePrefabs
participant PrefabStage
participant PrefabUtility
participant AssetDatabase
User->>ManagePrefabs: SavePrefabStage()
ManagePrefabs->>PrefabStage: get_current_prefab_stage()
alt prefabStage is null
ManagePrefabs-->>User: ErrorResponse(Not in prefab editing mode)
else prefabStage exists
ManagePrefabs->>ManagePrefabs: TrySavePrefabStage(prefabStage, prefabPath, errorMessage)
alt prefab contents root missing or save failed
ManagePrefabs-->>User: ErrorResponse(errorMessage)
else save succeeded
ManagePrefabs->>PrefabUtility: SaveAsPrefabAsset(prefabContentsRoot, prefabPath, saved)
PrefabUtility-->>ManagePrefabs: saved = true
ManagePrefabs->>PrefabStage: ClearDirtiness()
ManagePrefabs->>AssetDatabase: SaveAssets()
ManagePrefabs->>AssetDatabase: Refresh()
ManagePrefabs-->>User: SuccessResponse("Saved prefab stage changes", prefabPath, saved = true)
end
end
Sequence diagram for close_prefab_stage with saveBeforeClose using shared TrySavePrefabStagesequenceDiagram
actor User
participant ManagePrefabs
participant PrefabStage
participant PrefabUtility
participant AssetDatabase
User->>ManagePrefabs: ClosePrefabStage(saveBeforeClose = true)
ManagePrefabs->>PrefabStage: get_current_prefab_stage()
alt prefabStage is null
ManagePrefabs-->>User: ErrorResponse(Not in prefab editing mode)
else prefabStage exists
ManagePrefabs->>ManagePrefabs: TrySavePrefabStage(prefabStage, prefabPath, errorMessage)
alt save failed
ManagePrefabs-->>User: ErrorResponse(errorMessage)
else save succeeded
ManagePrefabs->>PrefabUtility: SaveAsPrefabAsset(prefabContentsRoot, prefabPath, saved)
PrefabUtility-->>ManagePrefabs: saved = true
ManagePrefabs->>PrefabStage: ClearDirtiness()
ManagePrefabs->>AssetDatabase: SaveAssets()
ManagePrefabs->>AssetDatabase: Refresh()
ManagePrefabs->>PrefabStage: CloseStage()
ManagePrefabs-->>User: SuccessResponse(Prefab stage closed)
end
end
Class diagram for updated ManagePrefabs prefab-stage save workflowclassDiagram
class ManagePrefabs {
<<static>>
+object SavePrefabStage()
+object ClosePrefabStage(bool saveBeforeClose)
-static bool TrySavePrefabStage(PrefabStage prefabStage, string prefabPath, string errorMessage)
}
class PrefabStage {
+string assetPath
+Object prefabContentsRoot
+Scene scene
+void ClearDirtiness()
}
class PrefabUtility {
+static void SaveAsPrefabAsset(Object prefabContentsRoot, string prefabPath, bool saved)
}
class AssetDatabase {
+static void SaveAssets()
+static void Refresh()
}
ManagePrefabs ..> PrefabStage : uses
ManagePrefabs ..> PrefabUtility : uses
ManagePrefabs ..> AssetDatabase : uses
File-Level Changes
Assessment against linked issues
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
|
Version note: I validated this fix in the repo’s Unity |
Description
Fixes prefab-stage saving so
save_prefab_stagewrites the prefab asset instead of trying to save the preview scene.Type of Change
Save your change type
Changes Made
save_prefab_stageto saveprefabStage.prefabContentsRootback toprefabStage.assetPathclose_prefab_stage(saveBeforeClose: true)Testing/Screenshots/Recordings
-testFilter ManagePrefabsStageTestsDocumentation Updates
tools/UPDATE_DOCS_PROMPT.md(recommended)tools/UPDATE_DOCS.mdRelated Issues
Fixes #1055
Additional Notes
Summary by Sourcery
Fix prefab stage saving to correctly persist changes to the underlying prefab asset and reuse a shared save workflow for explicit saves and save-before-close.
Bug Fixes:
Enhancements:
Tests:
Summary by CodeRabbit
Release Notes