Unity completions for Sublime Text

This might be a technical post, about Sublime Text. Or it could be a community post, about Unity editors. I don’t know yet. In any case it’s about Unity Completions, my first package for ST.

Unity Completions does one thing: It allows me to develop for Unity using ST. I know ST’s got its quirks, but it’s homey. And I eventually fell for its simultaneous editing – it’s stupendous! I’ve been using it quite contently for a long while. But the lack of Unity auto-completions, though, was dissatisfying. I couldn’t let it slide.

What Was

I searched the forums for solutions. There was no solution available for Boo developers. I found a post with a good solution for C-sharp developers only, based on CompleteSharp. And I found Jacob Pennock’s package. It fell short on content — it only offered completions for a handful of GUI-related completions — but it showed me how it can be done.

What Is

The next step was natural: I had to create a plugin that covers the full API. But I needed the info – the Unity API. I took a naive approach and wrote a crawler that just scans the entire scripting reference section and produces all the class names and definitions, including variables and function definitions. The output contained a little over 10,000 items. I then wrote a generator that converts it all to ST snippet files for 3 languages. It worked.

I wrote the package in March (9 months ago), when Unity 4.1 was out. I also tried to add it to Package Control, but those guys were wondering why it is should be added when a package with a similar name already exists (Jacob’s). At this point I tried to contact Jacob, but got no reply. By the time I got back to the subject, a new version of PC was in the pipes, soon to be released. So I decided to wait. Then I forgot about it for a while.

A couple of weeks ago I was reminded about it, and soon after added it to PC. It was immediately downloaded by users. In the first 14 days it was downloaded 128 times. It’s not a lot, but it seems a demand exists. The next step was to update the package – Unity v4.3.1 was recently released. I had to update the crawler because changes in Unity’s website broke it.

What’s Next

Now, two challenges remain. One is how to make the package smaller. The package currently holds snippets for a little over 12,000 Unity items. Each has two files (upper case and lower case – or it won’t work well) and all this for each of the 3 languages. This brings the total number of files to 72,399 and the entire package size to 26 MB.

Another challenge is how to keep updating the package easily. The process breaks whenever something changes in Unity’s website. Perhaps a better approach would be to dig into the DLLs?

Tagged , , . Bookmark the permalink.

7 Responses to Unity completions for Sublime Text

  1. shyam says:

    Thanks for releasing this. I installed and am playing around with it now.

    Regarding making the package smaller, the simplest thing would be to just split the three languages (C#, JS, Boo) into three separate packages. Almost all Unity projects select one of these languages to use as their primary development language, so it seems like a waste to have the other two included and enabled by default. If in the rare case someone needs code completion for two languages, they just install the two associated packages.

  2. Thijs says:

    Thank you for making this happening! Now I can finally switch to Sublime Text instead of using MonoDevelop! 😀

  3. Trevor says:

    Hmm… I’ve tried using this and it’s doing weird things. All I did was install it from package control. It’s entirely possible that I’m doing something boneheaded and don’t know it.

    The problem I’m having is that it spams the completions. Let’s say I want to instantiate a prefab. I’ll type “GameObject.” and nothing comes up—no completions, no members, nothing. Ok, so I type “I” and it shows me basically everything in Unity that starts with I. KeyCode.I, Rendering.StencilOp.Invert, etc. If I type Inst then Instantiate is the top choice. Ok. I hit return to select it. But it pops up the whole prototype for the function—parent and everything. I’m left with this:
    GameObject.Object.Instantiate(Object original, Vector3 position, Quaternion rotation);

    What’s going on here? Is there a setting that needs to be configured?

    MonoDevelop is really a poor code editor, not sure why it is even released. Being able to use Sublime would be fantastic.

    • Ofer Reichman says:

      What you are describing is expected behavior.

      1. When you type GameObject you should be offered completions:

      but as soon as you add a period the completions disappear. This is how Sublime’s auto-completion works – the period breaks the word.

      2. When you add the “I” after the period you get all kinds of completions, unrelated to GameObject:

      because, again, the period breaks the auto-completions and the completions you are offered are not related to GameObject, only to “I”.

      Alas, these are limitations of Sublime Text auto-complete plugins. It’s probably possible to write a better plugin that analyzes the source code and offers auto-completions according to context, but that’s far more complicated and would have to wait for another day.

      As for your case, Instantiate is a static function of Object, so the auto-complete (Object.Instantiate) is not wrong per se – it’s just out of context. Please delete the superfluous “Object” part manually.

  4. Trevor says:

    Thanks for the quick response!

Leave a Reply

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