Install VS Code and EmmyLua
中文 | English
Run this command at the repository root to replay the examples through the local Unity MCP.
python Docs/Manual/manual/tools/tutorials.py run install-vs-code-emmylua
Click to expand MCP actionsClick to collapse MCP actions
Prepare the teaching sample. The recipe provides ${variables}.
{
"variables": {},
"calls": [
{
"tool": "inspect",
"arguments": {
"path": "static:System.Environment/GetFolderPath(LocalApplicationData)"
},
"expect": {
"contains": "(String)"
},
"capture": {
"localApp": {
"regex": "\\(String\\) ([^\\r\\n]+)"
}
}
},
{
"tool": "inspect",
"arguments": {
"path": "static:System.Environment/GetFolderPath(UserProfile)"
},
"expect": {
"contains": "(String)"
},
"capture": {
"profile": {
"regex": "\\(String\\) ([^\\r\\n]+)"
}
}
}
]
}
1. Install the editor and the extension
- Choose the appropriate OS and architecture on the VS Code download page. Run the Windows installer. On macOS, unpack the download and drag Visual Studio Code.app into Applications.
- Open Extensions in the sidebar. The shortcut is Ctrl+Shift+X on Windows and Cmd+Shift+X on macOS. Search for
@id:tangzx.emmylua, open EmmyLua, and click Install. EmmyLua extension - If the command-line launcher is available, open a new terminal and run
code --list-extensions. Look fortangzx.emmylua.
Click to expand MCP actionsClick to collapse MCP actions
Checks the per-user installation on this Windows machine. Run the installer and Extensions actions manually.
[
{
"tool": "invoke",
"arguments": {
"path": "static:System.IO.File/Exists",
"args": [
"${localApp}/Programs/Microsoft VS Code/Code.exe"
]
},
"expect": {
"contains": "(Boolean) True"
}
},
{
"tool": "invoke",
"arguments": {
"path": "static:System.IO.Directory/GetDirectories",
"args": [
"${profile}/.vscode/extensions",
"tangzx.emmylua-*"
]
},
"expect": {
"contains": "tangzx.emmylua"
}
}
]
2. Configure an installation that still uses Java
Check the installed version and settings. The current upstream extension uses a Rust language server. Some older releases still offer the Java backend, including the 0.6.18 installation checked for this guide. Follow these steps if your selected backend requires Java. EmmyLua project
- Follow that version's requirements and choose the JDK for your OS and CPU. The legacy guide listed 1.8.0_181 as its minimum.
- In Extensions, open the gear menu for EmmyLua, choose Extension Settings, and find Java Home. Enter the JDK directory, such as
C:/Program Files/Java/jdk-17on Windows or/Library/Java/JavaVirtualMachines/jdk-17.jdk/Contents/Homeon macOS. Use your actual install path. - If you use Preferences: Open User Settings (JSON), the key is
emmylua.java.home. Use forward slashes in Windows paths to avoid escaping backslashes in JSON.
{
"emmylua.java.home": "C:/Program Files/Java/jdk-17"
}
Save, reload the VS Code window, and open a .lua file. If the language server fails to start, choose EmmyLua in the Output panel to check the missing dependency or path.
3. Add the project's API definitions
Open the Lua source folder in VS Code. Run XLua → Generate EmmyLua for LuaCallCSharp in Unity. Confirm that the project's Build/EmmyLua/ folder contains csharp.lua and api.lua. Add that folder to the VS Code workspace as editor definitions. Type WeaponAPI. in your script and check whether VS Code offers method names.
Click to expand MCP actionsClick to collapse MCP actions
[
{
"tool": "inspect",
"arguments": {
"path": "static:GeneralEditor.Utility_XluaDefineEditor"
},
"expect": {
"contains": "GenerateEmmyLuaForLuaCallCSharp"
}
}
]
Click to expand MCP actionsClick to collapse MCP actions
Generate or update Build/EmmyLua in your project. The default replay only checks the entry point.
[
{
"tool": "invoke",
"arguments": {
"path": "static:GeneralEditor.Utility_XluaDefineEditor/GenerateEmmyLuaForLuaCallCSharp",
"args": []
}
}
]
Continue with Lua breakpoint debugging.