Skip to content

Bug: UnityEvent Wiring Clears m_Calls Instead of Setting Them #631

@h2v9696

Description

@h2v9696

Description

When attempting to wire custom UnityEvent<T> fields via manage_components with set_property, MCP reports success but clears the m_Calls array instead of populating it with the provided callback data.

This affects both underscore-prefixed fields (_onEditClicked) and likely all UnityEvent fields.

Steps to Reproduce

  1. Create a MonoBehaviour with a UnityEvent field:
[SerializeField] private UnityEvent<MyType> _onCustomEvent;
  1. Wire the event manually in Unity Inspector (so m_Calls has data)

  2. Try to update via MCP:

{
  "tool": "manage_components",
  "params": {
    "action": "set_property",
    "target": 73018,
    "search_method": "by_id",
    "component_type": "NoteSystem.Views.UIRecurringNoteItem",
    "properties": {
      "_onEditClicked": {
        "m_PersistentCalls": {
          "m_Calls": [{
            "m_Target": {"instanceID": 73180},
            "m_TargetAssemblyTypeName": "NoteSystem.Views.UIRecurringNoteList, Assembly-CSharp",
            "m_MethodName": "OnItemEditClicked",
            "m_Mode": 0,
            "m_CallState": 2
          }]
        }
      }
    }
  }
}
  1. MCP returns: {"success": true, "message": "Properties set..."}

  2. Save scene and check .unity file - the event is now empty:

_onEditClicked:
  m_PersistentCalls:
    m_Calls: []

Expected Behavior

The m_Calls array should be populated with the provided callback:

_onEditClicked:
  m_PersistentCalls:
    m_Calls:
    - m_Target: {fileID: 794262283}
      m_TargetAssemblyTypeName: NoteSystem.Views.UIRecurringNoteList, Assembly-CSharp
      m_MethodName: OnItemEditClicked
      m_Mode: 0
      m_CallState: 2

Actual Behavior

  • MCP reports success
  • m_Calls array is cleared/emptied
  • Previously wired events are lost

Additional Context

  • MCP version: Latest from main branch
  • Unity version: 6000.1.2f1 (Unity 6)
  • The field IS found (no "property not found" error)
  • The issue is in serialization of the UnityEvent structure

Suggestion

The UnityEvent serialization likely needs special handling. When setting m_PersistentCalls.m_Calls, the code should:

  1. Create proper PersistentCall objects
  2. Resolve instanceID to proper Unity object references
  3. Use SerializedObject/SerializedProperty API for reliable serialization

Workaround

Edit .unity scene file directly using fileIDs instead of instanceIDs.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions