MCPcopy Create free account
hub / github.com/bigdra50/unity-cli / component_modify

Function component_modify

unity_cli/cli/commands/component.py:115–150  ·  view source on GitHub ↗

Modify a component property. Values are auto-parsed: integers, floats, booleans (true/false), JSON arrays ([1,2,3]), and JSON objects ({"r":1,"g":0,"b":0}) are converted to their appropriate types. Everything else is sent as a string. Examples: u component modify -t "Main C

(
    ctx: typer.Context,
    component_type: Annotated[str, typer.Option("--type", "-T", help="Component type name")],
    prop: Annotated[str, typer.Option("--prop", "-p", help="Property name to modify")],
    value: Annotated[
        str,
        typer.Option("--value", "-v", help="New value (auto-parsed: numbers, booleans, JSON arrays/objects)"),
    ],
    target: Annotated[str | None, typer.Option("--target", "-t", help="Target GameObject name")] = None,
    target_id: Annotated[int | None, typer.Option("--target-id", help="Target GameObject ID")] = None,
)

Source from the content-addressed store, hash-verified

113@component_app.command("modify")
114@handle_cli_errors
115def component_modify(
116 ctx: typer.Context,
117 component_type: Annotated[str, typer.Option("--type", "-T", help="Component type name")],
118 prop: Annotated[str, typer.Option("--prop", "-p", help="Property name to modify")],
119 value: Annotated[
120 str,
121 typer.Option("--value", "-v", help="New value (auto-parsed: numbers, booleans, JSON arrays/objects)"),
122 ],
123 target: Annotated[str | None, typer.Option("--target", "-t", help="Target GameObject name")] = None,
124 target_id: Annotated[int | None, typer.Option("--target-id", help="Target GameObject ID")] = None,
125) -> None:
126 """Modify a component property.
127
128 Values are auto-parsed: integers, floats, booleans (true/false),
129 JSON arrays ([1,2,3]), and JSON objects ({"r":1,"g":0,"b":0}) are
130 converted to their appropriate types. Everything else is sent as a string.
131
132 Examples:
133 u component modify -t "Main Camera" -T Camera --prop fieldOfView --value 90
134 u component modify -t "Cube" -T Transform --prop m_LocalPosition --value "[1,2,3]"
135 """
136 context: CLIContext = ctx.obj
137
138 if not target and target_id is None:
139 _exit_usage("--target or --target-id required", "u component modify")
140
141 parsed_value = _parse_cli_value(value)
142
143 result = context.client.component.modify(
144 target=target,
145 target_id=target_id,
146 component_type=component_type,
147 prop=prop,
148 value=parsed_value,
149 )
150 print_success(result.get("message", "Property modified"))
151
152
153@component_app.command("remove")

Callers

nothing calls this directly

Calls 5

_exit_usageFunction · 0.90
_parse_cli_valueFunction · 0.90
print_successFunction · 0.90
modifyMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected