Skip to content

[HIGH] add_component throws a raw null reference for stale instance IDs #69

Description

@Daliys

Problem

add_component resolves the target GameObject but does not check whether it exists before passing it to Undo.AddComponent.

Evidence

  • Editor/MCPServerMethods.Component.cs:32-38 resolves go with IdToObject(...) as GameObject.
  • The method validates the component type, but not go.
  • It then calls Undo.AddComponent(go, type) directly.

Impact

If the object was destroyed or the instance ID became stale, the RPC fails with a raw Unity/null reference exception instead of a clear GameObject not found style validation error.

Suggested fix

Check go == null immediately after resolution and return the same clear error pattern used by get_game_object, destroy_game_object, and related methods.

Source report

Imported from audit report item: correctness (11) / Editor/MCPServerMethods.Component.cs:35.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingneeds-triageImported or reported issue awaiting owner reviewpriority: highMajor broken workflow or broad compatibility failuresurface: componentComponent add, inspect, update, and schema workflowssurface: unity-editorUnity Editor package, windows, menus, or C# server surfacetype: correctnessIncorrect result, bad validation, or misleading success/failure behavior

    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