Skip to content

[MEDIUM] create_hierarchy is not one atomic Undo operation and property writes bypass Undo #134

Description

@Daliys

Problem

create_hierarchy creates a tree, adds components, and applies serialized properties without wrapping the whole client-facing operation in one Undo group. Property application also bypasses Undo.RecordObject.

Evidence

  • Editor/MCPServerMethods.Hierarchy.cs:47-56 recursively creates objects and mutates them after Undo.RegisterCreatedObjectUndo.
  • Editor/MCPServerMethods.Hierarchy.cs:61-68 adds components through Undo.AddComponent per component.
  • Editor/MCPServerMethods.Hierarchy.cs:71-107 applies component properties via SerializedObject.ApplyModifiedProperties() without Undo.RecordObject.
  • There is no Undo.SetCurrentGroupName / Undo.CollapseUndoOperations around the whole hierarchy creation.

Impact

A single create_hierarchy RPC can produce multiple Undo entries and non-undo-tracked property changes, making the operation non-atomic from a Unity user perspective.

Suggested fix

Wrap the full operation in a named Undo group, record component objects before property mutation, and collapse the group before returning.

Source report

Imported from audit report items:

  • unity-antipattern (6) / Editor/MCPServerMethods.Hierarchy.cs:47
  • unity-antipattern (6) / Editor/MCPServerMethods.Hierarchy.cs:71

Grouped because both describe the same create_hierarchy Undo contract gap.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingneeds-triageImported or reported issue awaiting owner reviewpriority: mediumImportant defect or workflow gap with workaroundsurface: json-rpcRaw JSON-RPC methods, schemas, or dispatch surfacesurface: unity-editorUnity Editor package, windows, menus, or C# server surfacetype: unity-antipatternUnity Editor lifecycle, Undo, selection, or API usage antipattern

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions