By Karol | 2017-06-26
As of writing this post, the latest version of Unity (5.6.1) comes bundled with Monodevelop version 5.9.6. If you’ve ever worked with Monodevelop for C# development, you’ll understand how painful it can be. So this post will describe an alternative to Monodevelop - Visual Studio Code, and how to set up Unity with it.
Visual Studio Code
Visual Studio code is a lightweight editor that is open source and until recently it was the only version of Visual Studio available on Mac. It offers extensions for almost every language you want to work in and as of version 5.5 Unity supports it natively.
Set up
To use Visual Studio Code with Unity there are a few steps you need to take to set it up.
Install the latest Visual Studio Code for your operating system
Go to the extension tab
in Code and install the following extensions:
Set up Unity to open Visual Studio Code by default. To do so, in the menu go to
Unity Preferences
and under theExternal Tools
tab, change the External Script Editor from ‘MonoDevelop (built-in)’ to ‘Code’.
After that Unity should be set up with Code!
How to debug
Now how do we actually debug our code using Code? Well this is where the Debugger for Unity plugin comes in.
First make sure your project is open in Visual Studio Code. If you’ve set up Visual Studio Code properly should be able to open your project the following ways:
- Via Unity:
- In the menu go to:
Assets > C# Project
- In the Inspector, click the gear
in the top right corner of a script component and select
Edit Script
- In the project explorer, double-click a script
- In the menu go to:
- Via Visual Studio Code:
- In the menu go to:
File > Open...
and select the top level folder of your Unity project
- In the menu go to:
Then after opening your project, go to the debugger tab
There if you set up the Unity Debugger properly you should see ‘Unity Editor’ as the selected option in the Debug dropdown:
From there all you have to do is click the green play button to the left of the ‘Unity Editor’ text, and you should see this menu pop up in the top middle of your code pane:
Now all that’s left to do is go to Unity and start the scene you want to debug. If you have any breakpoints set up, they should be hit in Visual Studio Code and from there you can debug to your heart’s content!
More links
Here are some helpful links if you want to learn more about Visual Studio Code, or how to use it with Unity: