AgentSkillsCN

Unity Development

在执行任何与Unity相关的工作时,务必激活此技能:在Assets/或Packages/下编辑C#脚本、编译Unity代码、运行测试、创建或修改GameObject/场景/预制体/资源、管理Unity包、更改项目设置、构建玩家、检查场景层级,或任何涉及Unity编辑器的操作。此技能提供了必要的工作流程,例如在文件创建后生成.meta文件,以及在代码更改后进行编译验证。在开始Unity工作前,务必加载此技能。

SKILL.md
--- frontmatter
description: >-
  MUST activate when performing ANY Unity-related task: editing C# scripts
  under Assets/ or Packages/, compiling Unity code, running tests, creating or
  modifying GameObjects/scenes/prefabs/assets, managing Unity packages, changing
  project settings, building the player, inspecting the scene hierarchy, or any
  operation involving the Unity Editor. This skill provides required workflows
  such as .meta file generation after file creation and compilation verification
  after code changes. Always load this skill before starting Unity work.

UniCli — Unity Editor CLI

UniCli lets you interact with Unity Editor directly from the terminal. The CLI (unicli) communicates with the Unity Editor over named pipes, so the Editor must be open with the com.yucchiy.unicli-server package installed.

RULES — Always Follow These

  1. After creating/modifying ANY file under Assets/ or Packages/: Run unicli exec AssetDatabase.Import --path "<path>" --json to generate .meta files. Never create .meta files manually — always let Unity generate them via this command. Unity requires .meta files for every asset — skipping this causes missing references, broken imports, and compilation errors. This applies to all file types: .cs, .asmdef, .asset, .prefab, directories, etc.
  2. After modifying C# code in the Unity project: Run unicli exec Compile --json to verify compilation. dotnet build only checks the client side — server-side code is compiled by Unity's own compiler.
  3. Always use --json when parsing output programmatically.
  4. If connection to Unity Editor fails: Retry 2–3 times, then ask the user to confirm Unity Editor is running with the project open.
  5. For platform-specific verification: Use unicli exec BuildPlayer.Compile --target <platform> --json to catch platform-specific errors (missing #if guards, unsupported APIs, etc.).

Prerequisites

Before running commands, verify that the CLI is installed and the Editor is reachable:

bash
unicli check

If unicli check reports that the server package is not installed, run unicli install to install it:

bash
unicli install

If the package is installed but the connection fails, make sure Unity Editor is open with the target project loaded. Retry a few times — the Editor may need a moment to start the server.

Discovering Commands

The project may have custom commands beyond the built-in set. Always run unicli commands to get the latest list:

bash
unicli commands        # human-readable
unicli commands --json # machine-readable

Use --help on any command to see its parameters:

bash
unicli exec GameObject.Find --help

Executing Commands

Run commands with unicli exec <command>. Pass parameters as --key value flags:

bash
unicli exec GameObject.Find --name "Main Camera"
unicli exec TestRunner.RunEditMode --testNameFilter MyTest

Boolean flags can be passed without a value:

bash
unicli exec GameObject.Find --includeInactive

Array parameters can be passed by repeating the same flag:

bash
unicli exec BuildPlayer.Build --locationPathName "Builds/Test.app" --options Development --options ConnectWithProfiler

Common options

  • --json — Output in JSON format (recommended for structured processing)
  • --timeout <ms> — Set command timeout in milliseconds
  • --no-focus — Don't bring Unity Editor to front
  • --help — Show command parameters and usage

Built-in Commands

CommandDescription
BuildPlayer.BuildBuild the player
BuildPlayer.CompileCompile player scripts for a build target
CompileCompile scripts and return results
Connection.ListList available connection targets (players/devices)
Connection.ConnectConnect to a target by ID, IP, or device ID
Connection.StatusGet current profiler connection status
Console.GetLogGet console log entries
Console.ClearClear console
PlayMode.EnterEnter play mode
PlayMode.ExitExit play mode
PlayMode.PauseToggle pause
Menu.ListList menu items
Menu.ExecuteExecute a menu item by path
TestRunner.RunEditModeRun EditMode tests
TestRunner.RunPlayModeRun PlayMode tests
GameObject.FindFind GameObjects by name, tag, or layer
GameObject.CreateCreate a new GameObject in the scene
GameObject.CreatePrimitiveCreate a primitive (Cube, Sphere, etc.)
GameObject.GetComponentsGet components on a GameObject
GameObject.SetActiveSet active state
GameObject.GetHierarchyGet scene hierarchy tree
GameObject.AddComponentAdd a component to a GameObject
GameObject.RemoveComponentRemove a component from a GameObject
GameObject.DestroyDestroy a GameObject from the scene
GameObject.SetTransformSet local position/rotation/scale
GameObject.DuplicateDuplicate a GameObject
GameObject.RenameRename a GameObject
GameObject.SetParentChange parent or move to root
Component.SetPropertySet a component property via SerializedProperty
Prefab.GetStatusGet prefab instance status
Prefab.InstantiateInstantiate a prefab into scene
Prefab.SaveSave GameObject as prefab asset
Prefab.ApplyApply prefab overrides
Prefab.UnpackUnpack a prefab instance
AssetDatabase.FindSearch assets
AssetDatabase.ImportImport an asset
AssetDatabase.GetPathGet asset path by GUID
AssetDatabase.DeleteDelete an asset
Project.InspectGet project info
PackageManager.ListList installed packages
PackageManager.AddAdd a package
PackageManager.RemoveRemove a package
PackageManager.SearchSearch the Unity package registry
PackageManager.GetInfoGet detailed info about an installed package
PackageManager.UpdateUpdate a package to a specific or latest version
AssemblyDefinition.ListList assembly definitions
AssemblyDefinition.GetGet assembly definition details
AssemblyDefinition.CreateCreate a new assembly definition
AssemblyDefinition.AddReferenceAdd an asmdef reference
AssemblyDefinition.RemoveReferenceRemove an asmdef reference
Scene.ListList all loaded scenes
Scene.GetActiveGet the active scene
Scene.SetActiveSet the active scene
Scene.OpenOpen a scene by asset path
Scene.CloseClose a loaded scene
Scene.SaveSave a scene or all open scenes
Scene.NewCreate a new scene
TypeCache.ListList types derived from a base type
TypeInspectInspect nested types of a given type

Settings Commands (auto-generated)

Commands for PlayerSettings, EditorSettings, and EditorUserBuildSettings are auto-generated at compile time to match your Unity version. Use unicli commands to see the full list.

PatternExampleDescription
<Settings>.InspectPlayerSettings.InspectGet all property values
<Settings>.Set<Property>PlayerSettings.SetCompanyNameSet a property
<Settings>.<Nested>.Set<Property>PlayerSettings.Android.SetMinSdkVersionSet a nested type property
<Settings>.<Method>PlayerSettings.SetScriptingBackendCall a Set/Get method

Enum values are passed as strings (e.g., "IL2CPP", "AndroidApiLevel28").

Common Workflows

Compile and check for errors:

bash
unicli exec Compile --json

List connection targets and check status:

bash
unicli exec Connection.List --json
unicli exec Connection.Status --json
unicli exec Connection.Connect '{"id":-1}' --json
unicli exec Connection.Connect '{"deviceId":"DEVICE_SERIAL"}' --json

Build the player:

bash
unicli exec BuildPlayer.Build --locationPathName "Builds/Test.app" --json
unicli exec BuildPlayer.Build --locationPathName "Builds/Test.app" --options Development --json
unicli exec BuildPlayer.Build --locationPathName "Builds/Test.app" --options Development --options ConnectWithProfiler --json
unicli exec BuildPlayer.Build --locationPathName "Builds/Test.app" --target Android --json

Compile player scripts for a specific build target:

bash
unicli exec BuildPlayer.Compile --json
unicli exec BuildPlayer.Compile --target Android --json
unicli exec BuildPlayer.Compile --target iOS --extraScriptingDefines MY_DEFINE --extraScriptingDefines ANOTHER_DEFINE --json

Run tests:

bash
unicli exec TestRunner.RunEditMode --json
unicli exec TestRunner.RunPlayMode --json
unicli exec TestRunner.RunEditMode --testNameFilter MyTest --json

Inspect the scene:

bash
unicli exec GameObject.GetHierarchy --json
unicli exec GameObject.Find --name "Main Camera" --json
unicli exec GameObject.GetComponents --instanceId 1234 --json

Create GameObjects:

bash
unicli exec GameObject.Create --name "Enemy" --json
unicli exec GameObject.Create --name "Child" --parent "Enemy" --json
unicli exec GameObject.Create --name "WithCollider" --components BoxCollider --json
unicli exec GameObject.CreatePrimitive --primitiveType Cube --json
unicli exec GameObject.CreatePrimitive --primitiveType Sphere --name "Ball" --json

Modify GameObjects:

bash
unicli exec GameObject.Rename --path "Enemy" --name "Boss" --json
unicli exec GameObject.SetTransform --path "Boss" --position 1,2,3 --json
unicli exec GameObject.Duplicate --path "Boss" --json
unicli exec GameObject.SetParent --path "Child" --parentPath "Boss" --json
unicli exec GameObject.Destroy --path "OldObject" --json

Manage components:

bash
unicli exec GameObject.AddComponent --path "Player" --typeName BoxCollider --json
unicli exec GameObject.RemoveComponent --componentInstanceId 1234 --json
unicli exec Component.SetProperty --componentInstanceId 1234 --propertyPath "m_IsKinematic" --value "true" --json

Prefab operations:

bash
unicli exec Prefab.GetStatus --path "MyPrefabInstance" --json
unicli exec Prefab.Instantiate --assetPath "Assets/Prefabs/Enemy.prefab" --json
unicli exec Prefab.Save --path "Player" --assetPath "Assets/Prefabs/Player.prefab" --json
unicli exec Prefab.Apply --path "MyPrefabInstance" --json
unicli exec Prefab.Unpack --path "MyPrefabInstance" --json

Scene operations:

bash
unicli exec Scene.List --json
unicli exec Scene.GetActive --json
unicli exec Scene.Open --path "Assets/Scenes/Level1.unity" --json
unicli exec Scene.Open --path "Assets/Scenes/Additive.unity" --additive --json
unicli exec Scene.SetActive --name "Level1" --json
unicli exec Scene.Save --all --json
unicli exec Scene.Close --name "Additive" --json
unicli exec Scene.New --empty --additive --json

Delete an asset:

bash
unicli exec AssetDatabase.Delete --path "Assets/Prefabs/Old.prefab" --json

Inspect and modify Unity settings:

bash
unicli exec PlayerSettings.Inspect --json
unicli exec PlayerSettings.SetCompanyName --value "MyCompany" --json
unicli exec PlayerSettings.Android.SetMinSdkVersion --value AndroidApiLevel28 --json
unicli exec PlayerSettings.SetScriptingBackend --buildTarget Android --value IL2CPP --json
unicli exec PlayerSettings.GetScriptingBackend --buildTarget Android --json
unicli exec EditorSettings.Inspect --json

Check console output:

bash
unicli exec Console.GetLog --json

Tips

  • Always use --json when you need to parse the output programmatically.
  • Run unicli commands --json first to discover all available commands, including project-specific custom commands.
  • If a command times out, increase the timeout: unicli exec Compile --timeout 60000.
  • If the connection to Unity Editor fails, retry a few times. If it still fails, confirm the Editor is running.