Game With Purpose

With a focus on cross-platform play and a history in game development giants, our team is creating a movement, powered by games that are just plain fun to play.

Bring down the borders. End the console wars. Pick up your controller and let's game with purpose.

Getting started with Visual Studio Code

By Karol on Jun 26, 2017

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.

  1. Install the latest Visual Studio Code for your operating system

  2. Go to the extension tab Extension Tab in Code and install the following extensions:

  3. Set up Unity to open Visual Studio Code by default. To do so, in the menu go to Unity Preferences and under the External Tools tab, change the External Script Editor from ‘MonoDevelop (built-in)’ to ‘Code’.

    Unity Preferences for Mac

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 Gear in the top right corner of a script component and select Edit Script
    • In the project explorer, double-click a script
  • Via Visual Studio Code:
    • In the menu go to: File > Open... and select the top level folder of your Unity project

Then after opening your project, go to the debugger tab Debugger Tab

There if you set up the Unity Debugger properly you should see ‘Unity Editor’ as the selected option in the Debug dropdown:

Unity Editor Option

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:

Debug options

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!

Here are some helpful links if you want to learn more about Visual Studio Code, or how to use it with Unity:

Share this post:
comments powered by Disqus