Unity 2017.3.0f3集成VSCode后多工作区及参数设置缺失问题求助
Hey there, let’s work through these three common integration headaches with Unity 2017.3.0f3 and VSCode—they’re totally solvable with a few tweaks:
1. Stop Multiple VSCode Workspaces From Opening
The root issue here is how Unity sends files to VSCode by default: it launches a new instance for each script instead of reusing an existing window/workspace. Here’s how to fix it:
- First, make sure VSCode is set as your default external script editor in Unity: go to
Edit > Preferences > External Tools, then selectVisual Studio Codefrom theExternal Script Editordropdown (if it’s not listed, useBrowseto locate yourCode.exe/Codeexecutable). - Once VSCode is selected, you should see an
External Script Editor Argsfield pop up (we’ll tackle the "missing args field" issue next if it doesn’t appear). In this field, paste:
The-r -g "$(File):$(Line)"-rflag tells VSCode to reuse the last active window, and-g "$(File):$(Line)"jumps straight to the correct line in the file. - If you still see multiple workspaces, manually open your Unity project’s root folder in VSCode first (File > Open Folder). This establishes a single workspace, so any subsequent script launches from Unity will open in that same window.
2. Prevent Workspace Count From Increasing After "Open C# Project"
This is directly tied to the parameter issue above. Once you’ve set the -r argument in the external editor settings, clicking Assets > Open C# Project will generate the necessary .vscode folder (with settings.json and launch.json) and open the project in a single VSCode window. After that, double-clicking scripts in Unity will no longer spawn new workspaces—they’ll open in the existing window.
3. Fix Missing "External Script Editor Args" Setting
If the args field doesn’t show up after selecting VSCode as your external editor, try these workarounds:
- Restart Unity: Sometimes the UI doesn’t refresh correctly after selecting a new editor. Close and reopen Unity, then check the
External Toolstab again. - Use a wrapper script (Windows/Mac): Create a simple script to act as a middleman between Unity and VSCode, which will pass the correct arguments automatically:
- For Windows: Create a
.batfile (e.g.,VSCodeUnityLauncher.bat) with this code:
Save it somewhere accessible, then in Unity’s@echo off code -r -g "%1:%2"External Script Editor, select this.batfile instead of directly selectingCode.exe. - For Mac: Create a
.shscript (e.g.,VSCodeUnityLauncher.sh) with this code:
Make it executable (run#!/bin/bash code -r -g "$1:$2"chmod +x VSCodeUnityLauncher.shin Terminal), then select it in Unity’s external editor settings.
- For Windows: Create a
- Edit Unity’s preferences file manually:
- On Windows: Navigate to
C:\Users\[YourUsername]\AppData\Roaming\Unity\EditorPreferences.asset(use VSCode or another YAML-compatible editor to open it). Find the section for external editor settings and add the args parameter with-r -g "$(File):$(Line)". - On Mac: Go to
~/Library/Preferences/com.unity3d.UnityEditor2017.x.plist(replacexwith your exact Unity version), then add the args string to the external editor entry. Use a plist editor if you don’t want to edit it manually.
- On Windows: Navigate to
All these steps should resolve your workspace duplication and missing settings issues. Let me know if you hit any snags!
内容的提问来源于stack exchange,提问作者Diptangshu Chakrabarty




