How to use Visual Studio Code as Unity3d script editor

vscode_256x256

Visual Studio Code has landed – a new code editor in the Visual Studio family that runs on both Windows, OSX and Linux.

My first thought when I saw Scott Hanselman show it on the BUILD 2015 keynote were how and if I could use this as the script editor for Unity3d C# scripts. MonoDev is just not my favorite editor.

The good news is that it is possible and simple!

On Windows

  1. Install Visual Studio Code :)
  2. Open Unity3d.
  3. Edit->Preferences->External Tools.
  4. In External Script Editor select Browse. Browse to C:\Users\USERNAME\AppData\Local\Code and select update.exe.
  5. In External Script Editor Args put in: –processStart Code.exe
  6. Close the window and you are set to go.

On OSX

  1. Install Visual Studio Code :)
  2. Unity->Preferences->External Tools
  3. In External Script Editor select Browse. Browse to and select Applications->Visual Studio Code.app.
  4. Close the window and you are set to go.

Applies to both Windows and OSX

The first time you double click on a C# script inside Unity3d, Visual Studio Code will not recognize the solution (.sln) file. Find the little “flame” in the bottom of Visual Studio Code, click it and select the .sln file for your project.

VisualStudioCodeProjectSelector

 

Actually this little “flame” is the real fixer for some Unity3d related problems, as with this solution VSCode will just open when ever you double click a C# script. So if you switch between more Unity3d projects, it’s not that ideal, as you need to go to File->Open Folder and select the folder with the .sln file in. Then you can select that .sln using this “flame” icon and you have IntelliSense and can start coding.

After you have done this, you have IntelliSense etc.

VSCodeIntellisenseUnity3d

I currently have not figured out the args that tells Visual Studio Code which file it should open. I know we in the Unity3d External Script Editor Args and put in “$(File)” with the file we double clicked. So it is just a matter of time before I figure out what the command in Visual Studio Code is. I have tried various combinations of –file, without any luck. If you know, let me know and I will this post.

Luckily, Visual Studio Code can do some awesome tricks, so you just hit CTRL+T (Windows) / CMD + T (OSX) and start to type the name of the script you would like to edit. Also remember to read about all the other features VSCode comes with.

  • Igor Cvetkov

    If You need to open files in external editor try to put at end of external script editor args %1, like this: –processStart Code.exe %1. This approach worked for me in Siebel Tools, Windows 7.

  • Max von Hippel
  • I haven’t tried that, as I have actually, after written this blogpost, gone back to MonoDev, as I am doing a lot of debugging (attaching to process) these days and as far as I know, VSCode cannot do that – yet.

  • Thanks, I’ll look into that :)

  • Patrick van Duyse

    I directed Unity to C:Program Files (x86)Microsoft VS Codecode.exe instead of C:USERNAMEAppDataLocalCodeupdate.exe, and used “$(File)” in the arguments instead of -processStart Code.exe and it opens files fine.

  • Cool and thanks for sharing :)

  • iluha_ua

    Just remove double quotes around $(File) – this works for me in Ubuntu 16.04