Skip to content

Examples and Tutorials

Ivan Murzak edited this page Nov 14, 2026 · 6 revisions

Examples and Tutorials

You talk to your agent in plain language; it chooses the tools. The RQL lines below show what happens underneath and also work directly from a terminal with unity-mcp-cli rql '<query>' (a query ending in set or call goes to rql-mutate, anything else to rql-query). When unsure, ask the agent, or run rql-schema.

Build a scene

Create a new scene with a ground plane, a capsule named Player at (0, 1, 0) with a Rigidbody, and save the scene.

editor | call CreateGameObject({name: "Ground", primitive: "Plane"})
editor | call CreateGameObject({name: "Player", primitive: "Capsule", position: [0, 1, 0]})
objects | where name == "Player" | call AddComponent("Rigidbody")
editor | call SaveScenes()

Inspect and bulk-edit

How many trees are in the scene? Make all rocks 50% bigger.

unity-mcp-cli rql 'objects | where name starts-with "Tree" | count'
unity-mcp-cli rql 'objects | where name starts-with "Rock" | set transform.localScale = transform.localScale * 1.5'
unity-mcp-cli rql 'roots | recurse children | select name active'

Assets and materials

Create a metallic golden material and put it on a new sphere.

editor | call CreateMaterial("Assets/Materials/Gold.mat")
unity.assets("t:Material")

Write and run C#

Write a PlayerController with WASD movement and attach it to Player.

The agent writes the script, waits for compilation and attaches the component. To run code once without a file:

unity-mcp-cli exec 'GameObject.FindObjectsOfType<Camera>().Length'
unity-mcp-cli compile ./MyGame   # compiler errors and warnings with file and line

Debug with the console

Read the console, find the cause of the NullReferenceException and fix it.

console
editor | call ClearConsole()

Test

Run all EditMode tests and fix what fails.

The agent uses tests-run. In CI, unity-mcp-cli test runs Unity's own -runTests in a batch-mode Editor (no plugin needed):

unity-mcp-cli test ./MyGame --junit-output junit.xml

See the result

Show me the Player from the front.

screenshot-isolated renders one object from a chosen angle. screenshot-scene-view, screenshot-game-view and screenshot-camera are hidden by default; show them in the window or with unity-mcp-cli configure ./MyGame --enable-tools screenshot-game-view.

Packages and lighting

Install Cinemachine. Bake the lighting of this scene.

package-search and package-add handle packages; the lighting RQL source has Bake, CancelBake and ClearBakedData.

Automate a whole setup

unity-mcp-cli create-project ./MyAIGame
unity-mcp-cli install-plugin ./MyAIGame
unity-mcp-cli login
unity-mcp-cli open ./MyAIGame
unity-mcp-cli wait-for-ready ./MyAIGame
unity-mcp-cli run-tool tests-run ./MyAIGame --input '{"testMode":"EditMode"}'
unity-mcp-cli close ./MyAIGame

run-tool, exec, test, compile, status and wait-for-ready accept --format json (one result envelope); all commands return documented exit codes (see the CLI README).

Tips

  • Describe the goal and the constraints; the agent finds the objects itself.
  • Prefer models that are good at tool use; results vary between models.
  • In VS Code with Copilot, use Agent mode.
  • Add your own tools for project-specific work: Custom Tools Development.

Clone this wiki locally