fix: register undo when deleting GameObjects via manage_gameobject#1135
fix: register undo when deleting GameObjects via manage_gameobject#1135Dallon wants to merge 1 commit into
Conversation
manage_gameobject(action="delete") called Object.DestroyImmediate directly, bypassing Unity's undo stack — manage_editor(action="undo") could not recover deleted objects. Switching to Undo.DestroyObjectImmediate restores the expected editor-undo behavior with full reference-graph restoration. The package already uses Undo.DestroyObjectImmediate correctly elsewhere (ComponentOps.cs, GameObjectComponentHelpers.cs); GameObjectDelete.cs was the outlier. The stale TODO/comment about "Unity 2022+" is from the 2021.3 era — Undo.DestroyObjectImmediate has been stable across all currently-supported Unity versions. Adds Delete_RegistersUndo_RestoresOnUndo test (delete then undo, assert restoration) to the existing ManageGameObjectDeleteTests baseline.
|
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)
📝 WalkthroughWalkthroughThis PR enables undo/redo support for GameObject deletion by switching from ChangesUndo-compatible GameObject deletion
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 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
manage_gameobject(action="delete")callsObject.DestroyImmediatedirectly, bypassing Unity's undo stack — somanage_editor(action="undo")cannot recover GameObjects deleted via MCP. This one-line fix switches toUndo.DestroyObjectImmediate, restoring expected editor-undo behavior with full reference-graph restoration.The package already uses
Undo.DestroyObjectImmediatecorrectly elsewhere —ComponentOps.cs:130,GameObjectComponentHelpers.cs:88,137.GameObjectDelete.cswas the outlier.Why the existing comment was stale
package.jsontargetsunity: "2021.3". The TODO is from that era —Undo.DestroyObjectImmediatehas been stable across all currently-supported Unity versions. The new undo test plus the existing 11-test baseline pass without regression on Unity 6000.3.10f1.Tests
Added
Delete_RegistersUndo_RestoresOnUndoto the existingManageGameObjectDeleteTestsclass — creates a GameObject vianew GameObject(name)(no prior undo registration), invokes the delete handler, asserts the object is gone, callsUndo.PerformUndo(), asserts restoration.Verified
ManageGameObjectDeleteTestsstill passmanage_gameobject(action="delete")→manage_editor(action="undo")restores the object with the sameinstanceIDRelated, not included
ManagePrefabs.cshas several other rawObject.DestroyImmediatecall sites (lines ~881, ~1112, ~1119, ~1136, ~1148, ~1198) with the same bug shape — they deserve a separate audit/PR. Kept out of this change to keep scope tight to themanage_gameobjectdelete path.Co-authored-by: Claude Opus 4.7 (1M context) noreply@anthropic.com
🤖 Generated with Claude Code
Summary by CodeRabbit
Bug Fixes
Tests