Using Unity with Sublime Text 2 (How to get everything set up)

Hey guys, I’ve seen a couple of threads around here asking questions about using Sublime Text 2 with Unity. I just want to say that I have been coding for Unity in Sublime for about the past year and it has been really wonderful.

I also wanted to share with you some of my plugins that I use to make the Unity/Sublime experience even better.
Here is a video about them so check it out.

They were all integrated into Sublime’s package control system about a week ago so they are very easy to install.
there are 3 plugins in total and they include:

  • Adding Syntax highlighting for C# and Javascript- A pluging that lets you highlight any Unity Class/function and right click to do a Unity reference search- A plugin that gives some snippets and autocompletes of Unity functions (this one is still a work in progress, fork my github package and help me out)

You can find more info about them and other tips for using Sublime (like how to get it to jump to the correct line from the console) on my blog post here.

3 Likes

I just figured out how to call into unity’s mono build system from within sublime text 2, so you can program in sublime and get error reporting back within sublime’s console, all without even running the unity editor.

Comment if you are interesting in knowing how.

Oh yes, tell us how! :smile:

And thanks for the other Sublime goodies btw!

Yes please!!

JacobPennock please share it!

Magnificent! Thanks for sharing these.

I'd be curious to learn about connecting with unity's mono build system, too.

Thanks for making this, awesome :)

Just discovered sublime today and loving it. Got your plugins and very pleased. How can I kick mono builds? Also got a c# complete that I want to config for unity completion.

Jacob thanks, thanks, and thanks again. I'm loving Sublime Text and you're my new hero :)

While waiting for Jacob to continue hooking together Sublime and Unity (especially jumping from errors in Unity to Sublime), I wrote a Sublime plugin that can run MonoDevelop builds. Just install the package and create a sublime project at the root level of the project (where the main .sln file is) and you can run a build from anywhere in that project. mdtools must be on your path.

https://github.com/rstehwien/Sublime-MonoDevelop

Works with Unity and normal MonoDevelop projects. At least lets you build, check for errors, and jump to those errors with F4 and Shift+F4. Doesn’t provide any runtime integration with Unity though.

Still trying to get CompleteSharp to work at all for me so I can get code completion.

1 Like

AMAZING! as soon as I get time I shall be doing this. I have none of those features at the moment, just using it as a glorified notepad... it is my fave IDE by far though. Thanks! :smile:

Hey, just posted a recap of all the (current) steps to integrate Sublime Text with Unity - mainly for personal use, but someone might find it useful. Here it is.

P.S. Jacob don’t disappear please! :slight_smile:

You might also want to include updating the C# bundle so Ctrl+R works properly. Basically go to the git below and copy the contents of Preferences, Syntaxes, and Snippets over what you have in your C# Package:
https://github.com/wintermi/csharp-tmbundle

Got that tip from the link below where you can also find a msbuild buildfile for those of you using visual studio.(where I got the beginnings of my monodevelop build).
http://shawnoster.com/blog/post/C-and-Sublime-Text-2-PROTIPS.aspx

Ditto :slight_smile:

Updated. Thanks a lot for the additional tips :)

I was able to get code completion working in sublime using CompleteSharp:

Setup something like the following in your CompleteSharp.sublime-settings

"completesharp_assemblies": [
    "D:\\Program Files (x86)\\Unity\\Editor\\Data\\Managed\\UnityEngine.dll",
    "D:\\Program Files (x86)\\Unity\\Editor\\Data\\Managed\\UnityEditor.dll",
    "D:\\Program Files (x86)\\Unity\\Editor\\Data\\Managed\\nunit.framework.dll",    "D:\\Users\\RES\\Documents\\code\\ArcaneProcedures\\ArcaneProceduresLib\\bin\\Debug\\ArcaneProceduresLib.dll"
    ],

The first few are unity’s (including NUnit) the last is one of my own libs… change paths an add more libs as needed. I had some trouble where system classes wouldn’t complete or would cause sublime to go unresponsive. I had both .NET and Mono on my path… think CompleteSharp got confused. Possible you will need to add mscorlib.dll with full path… but at this time I dont (and it could cause unresponsiveness if not same as sublime finds).

Yey! Thanks rstehwien :slight_smile:

rstehwien - First off great work, thanks a lot for doing this.

I've got everything working except being able to build with monodevelop (OSX).

I've added the mdtool path in the settings file but i'm not sure if i've got everything set correctly?

{
"working_dir": "${project_path:${folder}}",
"cmd": ["/Applications/Unity/MonoDevelop.app/Contents/MacOS/mdtool", "build", "-t:Build"],
"file_regex": "^\\s*(.*\\.cs)\\(([0-9]*)\\,([0-9]*)\\)\\:\\s*(.*)$",
"selector": "source.monodevelop, source.cs"
}

Thanks again.

Hey guys, I have not disappeared. I’m sorry that I have not been as active in this thread as I should have been.
I’ve been busy with client work and been traveling some. I am on the unity IRC most days under the name of UnicornForest if you ever are trying to chat with me.

These new autocompletes are just awesome! Great work rstehwien. I have been working on a new completes file that added all of Mathf and a couple completes for GetComponet and stuff for working with coroutines but now with this new autocompletes I don’t really feel like it is needed.

As far as piping Unity’s complier through to sublime’s console. I never released anything because, for one, its not as easy to setup as the other plugins and I don’t have a ton of time to provide support for it and I was worried lots of folks would have have trouble getting it to work and I would be bombarded with emails and support questions, secondly I could not really get it working well enough for me to feel very safe using it.

What I was doing was creating sublime project files that called unity’s xbuild (xbuild is mono’s version of msbuild) to compile everything instead of calling mdtool. Xbuild lets you inject a custom dll from the command line that gets used to collect the logging output. So I created my custom dll for logging to format the output in a way sublime would like. but that was a little tricky as it seems unity ships with a older version of xbuild and I have to go way back in the msdn reference to find out what functions I need. Also it seems there is a bug in the older version of xbuild that sometimes reports a strange error but its basically meaningless to us using Unity.

Also even through doing this way I have complete control over what is being feed to sublime I could not get the regrex to work correctly with the multiline output in my first screenshot. I can get it to work if I print all the errors and warnings each to a single line, but it doesn’t look as nice, but you can click on the errors to go to the line and step through them with the hotkeys and see the error info in sublime’s status bar.

All of this is windows only as well.

Anyway if one of you guys want to keep working at it, my project files look like this:

{
	"folders":
	[
		{
			"path": "Assets",
			"file_exclude_patterns": ["*.unity","*.guiskin","*.dll","*.meta" ,"*.prefab" ,"*.anim", "*.physicMaterial", "*.flare" , "*.cubemap" , "*.font" , "*.fontsettings" , "*.renderTexture"]
		}
	],
    "build_systems":
    [
        {
            "name": "Unity Mono",
			"cmd": ["C:\\Program Files (x86)\\Unity\\Editor\\Data\\Mono\\bin\\xbuild.bat", "${project_path}/${project_base_name}.sln","/noconsolelogger", "/logger:${project_path}\\SublimeUnity\\SublimeLogger.dll"],
		    "file_regex": "([^(]*)\\((\\d*),(\\d*)\\)\\s*(.*)"
        }
    ]
}

Here is a link my compiled logger and a template project file. To try and get it to work unzip the SublimeUnity folder to the root of you unity project, then rename the file MyUnityProject.sublime-project to the name of your project (this all might break if your project has spaces in its name) Then move it outside the SublimeUnity folder and into the root of your project (the folder containing assets and all the .sln files). Open one of you scripts in sublime and hit ctr+B to build and hope it works.

I’ve also included the source of my logger dll in case you want to try and mess with it. I’ve been building it with monodevelop.

Good luck everyone, and great work on getting a better auto complete solutions then I had going.

P.S. The nice things about them being project files is you can see and open all the scripts in you unity project through sublime.

P.P.S Really good luck everyone, I am sorry but I will not likely have a lot of time to try and provide support for this, so use at your own risk. I personally would not use it with production code. If you do have a problem the best way to ask me about it is to find me on the Unity IRC.

Here is what worked for me... but I don't have Unity installed on my mac machine; the mac is for my day job writing geospatial data visualization apps mainly for the insurance industry (not super exciting but good coworkers and it pays well)

{
    "working_dir": "${project_path:${folder}}",
    "cmd": ["/Applications/MonoDevelop.app/Contents/MacOS/mdtool", "build", "-t:Build"],
    "file_regex": "^\\s*(.*\\.cs)\\(([0-9]*)\\,([0-9]*)\\)\\:\\s*(.*)$",
    "selector": "source.monodevelop, source.cs"
}

Not really different than yours. Make sure your sublime project file is in the same directory as you .sln file. Also try going to the command line in that folder and running the same command to make sure it works

rstehwien$ /Applications/MonoDevelop.app/Contents/MacOS/mdtool build -t:Build

I missed "Unity" from the mdtool path for some reason - works now. Thanks!

Also out of interest is Sublime ever something UT could support officially? I've seen a fair few threads on the forum grumbling about Monodevelop and Sublime is definitely the best alternative I've come across.