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

Function gameobject_create

unity_cli/cli/commands/gameobject.py:67–121  ·  view source on GitHub ↗

Create a GameObject (empty or primitive) in the active scene. Omit --primitive for an empty GameObject. Pass one of the primitive types (Cube/Sphere/Capsule/Cylinder/Plane/Quad) to spawn a preconfigured mesh with collider. Transform options set the initial pose; each takes three flo

(
    ctx: typer.Context,
    name: Annotated[str, typer.Option("--name", "-n", help="GameObject name")],
    primitive: Annotated[
        str | None,
        typer.Option(
            "--primitive",
            "-p",
            help="Primitive type: Cube, Sphere, Capsule, Cylinder, Plane, Quad (omit for empty GameObject)",
        ),
    ] = None,
    parent: Annotated[
        str | None,
        typer.Option("--parent", help="Parent GameObject name"),
    ] = None,
    parent_id: Annotated[
        int | None,
        typer.Option("--parent-id", help="Parent GameObject instance ID"),
    ] = None,
    position: Annotated[
        tuple[float, float, float] | None,
        typer.Option("--position", help="Position (X Y Z)"),
    ] = None,
    rotation: Annotated[
        tuple[float, float, float] | None,
        typer.Option("--rotation", help="Rotation (X Y Z)"),
    ] = None,
    scale: Annotated[
        tuple[float, float, float] | None,
        typer.Option("--scale", help="Scale (X Y Z)"),
    ] = None,
)

Source from the content-addressed store, hash-verified

65@gameobject_app.command("create")
66@handle_cli_errors
67def gameobject_create(
68 ctx: typer.Context,
69 name: Annotated[str, typer.Option("--name", "-n", help="GameObject name")],
70 primitive: Annotated[
71 str | None,
72 typer.Option(
73 "--primitive",
74 "-p",
75 help="Primitive type: Cube, Sphere, Capsule, Cylinder, Plane, Quad (omit for empty GameObject)",
76 ),
77 ] = None,
78 parent: Annotated[
79 str | None,
80 typer.Option("--parent", help="Parent GameObject name"),
81 ] = None,
82 parent_id: Annotated[
83 int | None,
84 typer.Option("--parent-id", help="Parent GameObject instance ID"),
85 ] = None,
86 position: Annotated[
87 tuple[float, float, float] | None,
88 typer.Option("--position", help="Position (X Y Z)"),
89 ] = None,
90 rotation: Annotated[
91 tuple[float, float, float] | None,
92 typer.Option("--rotation", help="Rotation (X Y Z)"),
93 ] = None,
94 scale: Annotated[
95 tuple[float, float, float] | None,
96 typer.Option("--scale", help="Scale (X Y Z)"),
97 ] = None,
98) -> None:
99 """Create a GameObject (empty or primitive) in the active scene.
100
101 Omit --primitive for an empty GameObject. Pass one of the primitive types
102 (Cube/Sphere/Capsule/Cylinder/Plane/Quad) to spawn a preconfigured mesh
103 with collider. Transform options set the initial pose; each takes three
104 floats (X Y Z).
105
106 Examples:
107 u gameobject create -n Empty
108 u gameobject create -n Wall -p Cube --position 0 0 5 --scale 10 2 1
109 u gameobject create -n Floor -p Plane --rotation 0 0 0
110 """
111 context: CLIContext = ctx.obj
112 result = context.client.gameobject.create(
113 name=name,
114 primitive_type=primitive,
115 parent=parent,
116 parent_id=parent_id,
117 position=list(position) if position else None,
118 rotation=list(rotation) if rotation else None,
119 scale=list(scale) if scale else None,
120 )
121 print_success(result.get("message", f"Created: {name}"))
122
123
124@gameobject_app.command("modify")

Callers

nothing calls this directly

Calls 3

print_successFunction · 0.90
createMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected