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

Function gameobject_find

unity_cli/cli/commands/gameobject.py:26–62  ·  view source on GitHub ↗

Locate GameObjects in the active scene by name or instance ID. Returns all matching objects with their instance IDs — use the ID for precise follow-up commands when multiple share a name. Examples: u gameobject find -n Player u gameobject find --id 12345

(
    ctx: typer.Context,
    name: Annotated[str | None, typer.Option("--name", "-n", help="GameObject name")] = None,
    id: Annotated[int | None, typer.Option("--id", help="Instance ID")] = None,
    json_flag: Annotated[
        bool,
        typer.Option("--json", help="Output as JSON"),
    ] = False,
)

Source from the content-addressed store, hash-verified

24@gameobject_app.command("find")
25@handle_cli_errors
26def gameobject_find(
27 ctx: typer.Context,
28 name: Annotated[str | None, typer.Option("--name", "-n", help="GameObject name")] = None,
29 id: Annotated[int | None, typer.Option("--id", help="Instance ID")] = None,
30 json_flag: Annotated[
31 bool,
32 typer.Option("--json", help="Output as JSON"),
33 ] = False,
34) -> None:
35 """Locate GameObjects in the active scene by name or instance ID.
36
37 Returns all matching objects with their instance IDs — use the ID for
38 precise follow-up commands when multiple share a name.
39
40 Examples:
41 u gameobject find -n Player
42 u gameobject find --id 12345
43 """
44 context: CLIContext = ctx.obj
45
46 if not name and id is None:
47 _exit_usage("--name or --id required", "u gameobject find")
48
49 result = context.client.gameobject.find(name=name, instance_id=id)
50 if _should_json(context, json_flag):
51 print_json(result)
52 else:
53 objects = result.get("objects", [])
54 if is_no_color():
55 rows = [[obj.get("name", "Unknown"), str(obj.get("instanceID", ""))] for obj in objects]
56 print_plain_table(["Name", "ID"], rows, header=False)
57 else:
58 print_line(f"[bold]Found {len(objects)} GameObject(s)[/bold]")
59 for obj in objects:
60 obj_name = escape(obj.get("name", "Unknown"))
61 obj_id = obj.get("instanceID", "")
62 print_line(f" {obj_name} (ID: {obj_id})")
63
64
65@gameobject_app.command("create")

Callers

nothing calls this directly

Calls 8

_exit_usageFunction · 0.90
_should_jsonFunction · 0.90
print_jsonFunction · 0.90
is_no_colorFunction · 0.90
print_plain_tableFunction · 0.90
print_lineFunction · 0.90
findMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected