Using C# 6 in Unity with Sublime Text 3

Jak Tiano
3 min readJun 18, 2018

As someone who spends 50+ hours every week writing C# code for Unity, I wish I had taken the time to figure this out a year ago. Better string interpolation and the null propagation operator (among other new features) have already made my life so much easier.

For those who don’t know, that means this:

private void StopLoadingTween () {    if ( _activeTweens != null ) {
var loadingTween = _activeTweens.GetTween("loading");
if ( loadingTween != null ) {
loadingTween.Kill ();
}
}
}

can become this:

private void StopLoadingTween () {

_activeTweens?.GetTween("loading")?.Kill ();
}

Especially when working with MonoBehaviours, this can make writing code faster, cleaner, and more fun.

I’m sure that by using Visual Studio you’ve probably been able to take advantage of C# 6 in Unity for some time now, but as someone whose workflow is so grounded in Sublime’s speed and simplicity, I’ve failed to move to VS on multiple attempts. For others like me who can’t quite leave Sublime, but want to use a more recent version of C#, here’s how I managed it.

Disclaimer: I have no idea how OmniSharp works, and this was only accomplished through a few hours of digging and brute force. If you know something I don’t that can make any part of this better, feel free to leave suggestions in a reply. Also all of this is at your own risk. If you can, please try this out somewhere other than your primary dev environment first. Also, I’m doing all of this on macOS, so that’s what all the terminal commands are for.

Step 0a: How to use SublimeText 3 with Unity

If you don’t currently use SublimeText 3 with Unity, this is the setup instructions I used a few years ago to get started: http://www.radjor.com/blog/p/65. I love Sublime, but if you don’t already use it, it’s probably not best to jump in now: I’m constantly having to use life support to continue using it.

Step 0b: Enabling C# 6 support in Unity

To even use these C# features in your Unity project regardless of which environment you are writing your scripts, you’ll have to enable the .NET 4.x runtime for your project. “Edit>Project Settings>Player” will open the player settings in the inspector. Then under “Other Settings” change the “Scripting Runtime Version” to .NET 4.x Equivalent, and make sure the “API Compatibility Level” is also set to .NET 4.x.

Step 0c: Uninstall OmniSharp-Sublime (if installed)

Honestly, I’m not sure if this is necessary. For some reason my version of OmniSharp-sublime was different than the most recent on on github. If you have custom settings in any of the config files, you’re on your own with migrating those. However, if you’re mostly running vanilla omnisharp-sublime, there is probably no downside to uninstalling.

Step 1: Navigate to your sublime Packages directory

Open terminal, and enter the following command:

cd ~/Library/Application\ Support/Sublime\ Text\ 3/Packages

Step 2: Clone a fresh copy of omnisharp-sublime

This command will pull down a fresh copy of the master branch of omnisharp-sublime into your packages folder, as a folder named “OmniSharp”

git clone --recursive https://github.com/OmniSharp/omnisharp-sublime.git OmniSharp

Step 3: Build OmniSharp

The next two commands change the directory to the new OmniSharp folder you created in the last step, and then executes the build script. To be honest though, I’m not sure if this step is necessary.

cd OmniSharp
./build.sh

Step 4: Change OmniSharp settings

Inside the same “/Packages/OmniSharp” folder, open the “OmniSharpSublime.sublime-settings” file. In there, look for the line that says:

“omnisharp_server_active”:”roslyn”

Change this to:

“omnisharp_server_active”:”prebuilt-roslyn”

Step 5: Launch Sublime

If Sublime was open already, close it and relaunch. When it opens, it should load your project. Sometimes things get wonky and you might manually need to use the command palette (cmd+shift+P) to use the “OmniSharpSublime: Reload Solution” command, or the “OmniSharpSublime: Restart Server” command.

Next steps

I’m not really sure of the long-term viability of this solution. It seems to be okay, but sometimes when opening sublime I get some weird issues getting the omnisharp-server to start. I also tend to keep Visual Studio linked as my default script editor in Unity so that I can use “Assets>Open C# Project” to rebuild and update my .sln and .csproj files. Hopefully at the very least, this post will help the last few Sublime holdouts like myself find each other and trade notes on how to keep this a viable place for text editing in Unity.

--

--

Jak Tiano

I love to bring order to the world in a way that magnifies the fun of it all. I spend most of my time writing code and in the kitchen.