Summary
The manage_components tool with set_property action fails when trying to set reference-type fields (e.g., Button component references) on MonoBehaviour components. The tool validation rejects the input format for reference properties.
Environment
- Unity MCP Tool: Latest version
- Unity Version: 2022.3.62f1
- Use Case: Configuring UI button component references in scene
Problem Description
Attempted Operation
Trying to set the button field (a Button component reference) on a custom MenuPanelButton MonoBehaviour:
Tool: manage_components
Action: set_property
Target: GameObject with instanceID
Component Type: Custom MonoBehaviour class
Properties: {"button": {"instanceID": "29690"}}
Code Example
public abstract class MenuPanelButton : MonoBehaviour
{
[SerializeField] protected Button button;
// ... other fields
}
Attempted Tool Calls
Attempt 1: Direct instanceID reference
{
"action": "set_property",
"target": "29690",
"component_type": "Watermelon.SquadShooter.MenuInventoryButton",
"properties": {
"button": {"instanceID": "29690"}
}
}
Error:
1 validation error for call[manage_components]
properties
Input should be a valid dictionary [type=dict_type, input_value='{"button": {"instanceID": "29690"}}', input_type=str]
Attempt 2: String instanceID
{
"action": "set_property",
"target": "29690",
"component_type": "Watermelon.SquadShooter.MenuInventoryButton",
"properties": {
"button": "29690"
}
}
Result: No error, but field not set (likely treated as string, not reference)
Expected Behavior
The tool should accept a reference format like:
{
"properties": {
"button": {"instanceID": 29690}
}
}
Or:
{
"properties": {
"button": {"gameObjectInstanceID": 29690}
}
}
And correctly set the component reference on the target MonoBehaviour.
Current Workaround
Created an Editor script using reflection to set reference fields:
var buttonField = typeof(MenuPanelButton).GetField("button",
BindingFlags.NonPublic | BindingFlags.Instance);
buttonField.SetValue(menuButton, buttonComponent);
Suggested Solution
- Add support for reference-type properties in
set_property action
- Define clear format for component/GameObject references (e.g.,
{"instanceID": 12345})
- Add documentation examples for setting reference fields
- Consider adding a dedicated
set_reference action for reference-type fields
Impact
This limitation prevents automated scene configuration via MCP tools, requiring manual Editor scripting or manual Inspector configuration for any reference-type fields.
Additional Context
- Primitive types (int, float, string, bool) work correctly with
set_property
- Only reference types (Component, GameObject, Transform, etc.) have this issue
- The validation error suggests the tool expects a flat dictionary, not nested objects
Reproduction Steps
- Create a MonoBehaviour with a reference field:
public class TestScript : MonoBehaviour
{
[SerializeField] private Button myButton;
}
- Add the script to a GameObject in scene
- Try to set
myButton reference via manage_components tool
- Observe validation error or silent failure
Related Use Cases
- Setting up UI component references
- Configuring scene object dependencies
- Automated testing setup
- Batch scene configuration
Summary
The
manage_componentstool withset_propertyaction fails when trying to set reference-type fields (e.g., Button component references) on MonoBehaviour components. The tool validation rejects the input format for reference properties.Environment
Problem Description
Attempted Operation
Trying to set the
buttonfield (aButtoncomponent reference) on a customMenuPanelButtonMonoBehaviour:Code Example
Attempted Tool Calls
Attempt 1: Direct instanceID reference
{ "action": "set_property", "target": "29690", "component_type": "Watermelon.SquadShooter.MenuInventoryButton", "properties": { "button": {"instanceID": "29690"} } }Error:
Attempt 2: String instanceID
{ "action": "set_property", "target": "29690", "component_type": "Watermelon.SquadShooter.MenuInventoryButton", "properties": { "button": "29690" } }Result: No error, but field not set (likely treated as string, not reference)
Expected Behavior
The tool should accept a reference format like:
{ "properties": { "button": {"instanceID": 29690} } }Or:
{ "properties": { "button": {"gameObjectInstanceID": 29690} } }And correctly set the component reference on the target MonoBehaviour.
Current Workaround
Created an Editor script using reflection to set reference fields:
Suggested Solution
set_propertyaction{"instanceID": 12345})set_referenceaction for reference-type fieldsImpact
This limitation prevents automated scene configuration via MCP tools, requiring manual Editor scripting or manual Inspector configuration for any reference-type fields.
Additional Context
set_propertyReproduction Steps
myButtonreference viamanage_componentstoolRelated Use Cases