Using Visual Studio Code with Unity3D on Linux

So you’ve set up Unity3D on Linux, but now you need a good text editor to write your scripts. In that case, you can consider using Visual Studio Code (VS Code for short), a cross-platform text editor from Microsoft. VS Code has become hugely popular for web development, but its versatility means that it can also be used for programming in languages such as C#, Python, Go, etc.

Note that I am using Linux Kubuntu 20.04 (LTS) and Unity3D 2020.3.15f2 (LTS).

Installing VS Code

The VS Code documentation explains how to set up VS Code on Linux. The easiest option is via the snap package manager as follows:

sudo snap install --classic code

Alternatively, you can download and install a .deb or .rpm package of you prefer. See the documentation for details.

Configuring the External Editor in Unity3D

Next, we’ll configure Unity3D to use VS Code as its external editor for scripts.

First, you’ll need to have the “Visual Studio Code Editor” package installed. This is set up for you when you create a new project, but you can double-check via the Window menu and then Package Manager:

Visual Studio Code Editor 1.2.3 is installed.

With that in place, go to the Edit menu and then Preferences… and switch to the External Tools tab. Click the dropdown next to the “External Script Editor” setting and then Browse… for the VS Code executable. If you don’t know where it is, use the following command in a terminal to locate it. In my case it’s at /snap/bin/code.

whereis code
To set VS Code as the Unity3D script editor, go to the Edit menu -> Preferences…, switch to the External Tools tab and then set the value of “External Script Editor” to the path to the VS Code executable.

Now, if you create a C# script in Unity3D and open it, it should open in VS Code.

Configuring VS Code for Unity3D

You can now write C# scripts for Unity3D in VS Code and you have syntax highlighting to help you. However, Intellisense — the helpful suggestions that pop up e.g. when you try to access an object’s properties — doesn’t work yet. You also don’t get any indication of C# syntax errors. Let’s fix this so that we can write Unity3D scripts in a comfortable environment.

First, install the .NET Core SDK on Linux by following the instructions in the relevant documentation.

Update 14th May 2023: The rest of this section below is now obsolete. A breaking change was applied to OmniSharp last year that removed the omnisharp.useGlobalMono setting and changed the default value of the omnisharp.useModernNet setting to true. This way, you can install a recent version of the .NET Core SDK (e.g. 6.0) and configure it in the VS Code Omnisharp settings (Ctrl+Shift+P, search for “omnisharp sdk”, set path and version). It’s not necessary to install Mono.

Update 12th June 2023: After much fiddling around, I found that Intellisense only really works if you set useModernNet to false. OmniSharp seems to download a Mono version of its own, so I’m not sure whether a .NET Core SDK is necessary at all, without tinkering further.

Next, head to the Mono Download page, and follow the first set of instructions to add the Mono repository to your system. Then, for the second step, install mono-complete instead of mono-devel as shown below. (Note: don’t run the following command before first setting up the Mono repository. The version coming from the Ubuntu repositories doesn’t seem to play well with VS Code and Unity3D.)

sudo apt-get install mono-complete

Then, in VS Code, go to the Extensions tab on the left, search for “C#”, and install the first extension that comes up:

Install the C# extension for Visual Studio by Omnisharp.

Open up settings via File menu -> Preferences -> Settings (or Ctrl+, (control comma)) and search for “Omnisharp: Use Global Mono“, then set its value to “always”. Click “Restart Omnisharp” from the notification that appears at the bottom-right. You can also restart Omnisharp at any time by pressing Ctrl+Shift+P and selecting “OmniSharp: Restart OmniSharp”.

In Settings, set “Omnisharp: Use Global Mono” to “always” and then restart OmniSharp.

Still No Intellisense?

The above steps are usually enough to get Intellisense working, but as I’m writing this right now, it doesn’t seem to work. To fix this, I had to downgrade the C# extension in VS Code, as follows:

  1. Go into the Extensions tab in VS Code.
  2. Locate the C# extension by OmniSharp.
  3. Click the small arrow next to the “Uninstall” button.
  4. Select “Install Another Version…”
  5. In my case, the latest version (1.23.14) was released just 3 days ago. I went for an older version that had been around for a couple of months (1.23.12).
  6. Click the “Reload Required” button.
  7. Watch the Output and wait for OmniSharp to finish downloading and installing.

Testing Intellisense

VS Code should now provide Intellisense as you type, and you should also see syntax errors called out via both a squiggly red underline and in the Problems window below.

Intellisense and errors both work.

You should now be all set up. Happy game development!

8 thoughts on “Using Visual Studio Code with Unity3D on Linux”

  1. Thanks for the great “how to”!
    Intellisense didn’t work out of the box for me too.
    The fix was to change “omnisharp.useModernNet” to false in the Settings.

  2. Hi there,
    i got
    “Use of uninitialized value $libs in concatenation (.) or string at /usr/sbin/mono-xsp4-update line 216.”
    when it tried to install mono with
    > sudo apt install mono-complete

    Nevertheless i tried the rest and i couldn’t find the setting “Omnisharp: Use Global Mono” in VS Code.
    Even if i set “omnisharp.useModernNet” to false and set the mono path to /usr/bin/mono the extension C# could not find the mono installation and i get
    “The .NET Core SDK cannot be located: A valid dotnet installation could not be found. .NET Core debugging will not be enabled. Make sure the .NET Core SDK is installed and is on the path.” after restarting omnisharp.

  3. “In my case, the latest version (1.23.14) was released just 3 days ago. I went for an older version that had been around for a couple of months (1.23.12).”

    Solved the issue! 🙂


Leave a Reply

Your email address will not be published. Required fields are marked *