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

Function asset_prefab

unity_cli/cli/commands/asset.py:28–50  ·  view source on GitHub ↗

Save a scene GameObject (and its children) as a Prefab asset. Examples: u asset prefab -s Player -p Assets/Prefabs/Player.prefab u asset prefab --source-id 12345 -p Assets/Prefabs/Enemy.prefab

(
    ctx: typer.Context,
    path: Annotated[str, typer.Option("--path", "-p", help="Output path (e.g., Assets/Prefabs/My.prefab)")],
    source: Annotated[str | None, typer.Option("--source", "-s", help="Source GameObject name")] = None,
    source_id: Annotated[int | None, typer.Option("--source-id", help="Source GameObject instance ID")] = None,
)

Source from the content-addressed store, hash-verified

26@asset_app.command("prefab")
27@handle_cli_errors
28def asset_prefab(
29 ctx: typer.Context,
30 path: Annotated[str, typer.Option("--path", "-p", help="Output path (e.g., Assets/Prefabs/My.prefab)")],
31 source: Annotated[str | None, typer.Option("--source", "-s", help="Source GameObject name")] = None,
32 source_id: Annotated[int | None, typer.Option("--source-id", help="Source GameObject instance ID")] = None,
33) -> None:
34 """Save a scene GameObject (and its children) as a Prefab asset.
35
36 Examples:
37 u asset prefab -s Player -p Assets/Prefabs/Player.prefab
38 u asset prefab --source-id 12345 -p Assets/Prefabs/Enemy.prefab
39 """
40 context: CLIContext = ctx.obj
41
42 if not source and source_id is None:
43 _exit_usage("--source or --source-id required", "u asset prefab")
44
45 result = context.client.asset.create_prefab(
46 path=path,
47 source=source,
48 source_id=source_id,
49 )
50 print_success(result.get("message", f"Prefab created: {path}"))
51
52
53@asset_app.command("scriptable-object")

Callers

nothing calls this directly

Calls 4

_exit_usageFunction · 0.90
print_successFunction · 0.90
create_prefabMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected