-
Notifications
You must be signed in to change notification settings - Fork 756
Description
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_propertyaction - Define clear format for component/GameObject references (e.g.,
{"instanceID": 12345}) - Add documentation examples for setting reference fields
- Consider adding a dedicated
set_referenceaction 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
myButtonreference viamanage_componentstool - Observe validation error or silent failure
Related Use Cases
- Setting up UI component references
- Configuring scene object dependencies
- Automated testing setup
- Batch scene configuration