Search Unity

  1. Looking for a job or to hire someone for a project? Check out the re-opened job forums.
    Dismiss Notice
  2. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Sublime as external editor on OS X, always opens a new window

Discussion in 'Import Formats & External Tools' started by nicmarxp, Jan 7, 2018.

  1. nicmarxp

    nicmarxp

    Joined:
    Dec 3, 2017
    Posts:
    374
    When I double click to edit a script inside Unity, Sublime opens my project with the correct file loaded. The second time I do it, a new instance of Sublime opens. And this keeps on forever.

    I see a lot of thread about this, but no solution that works. I already have this in Sublime settings:
    "open_files_in_new_window": false,

    Doesn't make a difference.

    However, when I open sublime from the command line, like this:
    /Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl test.txt:5

    I can run that many times, and it still only opens one Sublime instance. I tried placing this in a subl.command-file, but that can't be selected as the external editor.

    I tried to make an "App" called "Sublime Unity.app" using the Appify script from the command file, and assign the app as an external editor, but when I click files to edit, nothing happens.

    I'm out of ideas, so currently I just switch to Sublime, and pick the file to edit from the project tree structure, but sometimes it would be easier to jump straight from Unity.

    Any tips would help!
     
  2. Marble

    Marble

    Joined:
    Aug 29, 2005
    Posts:
    1,233
    Have you filed a bug? This happens to me, too, and it's maddening.
     
  3. bitinn

    bitinn

    Joined:
    Aug 20, 2016
    Posts:
    724
    I can confirm this is the case for me too, is there anyone at Unity willing to look into this?

    At least we need to know whether this is a Unity problem or Sublime problem (but as demonstrate by OP, using `subl` command we can't reproduce this problem). I would love to know how Unity invoke sublime, the exact command I mean.
     
  4. bitinn

    bitinn

    Joined:
    Aug 20, 2016
    Posts:
    724
    By the way, if I have Sublime closed when I click in Unity console, then all subsequent window will be the same Sublime window. But if I have Sublime opened, then Unity will launch a separate Sublime window no matter what I do.
     
  5. Marble

    Marble

    Joined:
    Aug 29, 2005
    Posts:
    1,233
    Are you still getting this problem in 2017.3.1? It was fixed for me with this version. I did have to clear the cline arguments from the external editor preferences in Unity, though.
     
  6. bitinn

    bitinn

    Joined:
    Aug 20, 2016
    Posts:
    724
    On 2017.3.0f3 at the moment, didn't know there is a 3.1, will look into it later today.

    By the way this is my setup:

    Screen Shot 2018-02-12 at 14.07.44.png
     
  7. bitinn

    bitinn

    Joined:
    Aug 20, 2016
    Posts:
    724
    OK looks like they fix it in 2017.3.1, I can't reproduce this issue now.
     
    Marble likes this.
  8. nicmarxp

    nicmarxp

    Joined:
    Dec 3, 2017
    Posts:
    374
    Great I will look into this!
     
  9. booferei

    booferei

    Joined:
    Sep 29, 2016
    Posts:
    17
    The bug still occurs if the "External Script Editor Args" field is set. Clear it. (see unity preferences image above)
     
    James_Cooper likes this.
  10. nicmarxp

    nicmarxp

    Joined:
    Dec 3, 2017
    Posts:
    374
    Thanks, however I just switched to VS Code, since the Omnisharp/resharper features work so much better. There are still some settings I couldn't reproduce in VS Code, but I find it more stable, and I was surprised that it was so similar to Sublime in how it works, for being a Microsoft product :)
     
  11. melgeorgiou

    melgeorgiou

    Joined:
    Nov 3, 2012
    Posts:
    677
    Hi everyone,

    Sorry to revive an old thread but as a sublime text fan myself, this issue was driving me nuts so I came up with my own workaround for Mac. The issue occurs because Unity doesn't allow us to select the 'real' app inside the Sublime Text folder and it is somehow launching the app in a strange way which opens multiple instances.

    Anyway, my workaround *should* work even if you update Sublime and also allows you to open files at a specific line. So here it is:

    1) Make sure you can easily open Sublime Text 3 from the terminal by setting it up in your bash profile. I followed the step by step instructions here so you can easily launch it by typing 'sublime':

    https://techtalktone.wordpress.com/2015/02/01/open-sublime-text-3-from-terminal-on-mac-os-x/

    2) This is where the solution gets creative, lol. Open the built-in 'Automator' app on the Mac (it's awesome!) and choose to create a new Application. You only need a single 'Run Shell Script' action using the code below (make sure you set Pass Input 'as arguments'):

    AutomatorSetup.png

    Once you've done that, save the automator application to your Applications Folder. I called mine "Sublime Text Launcher For Unity".

    3) Back in Unity, you can now select your External Script Editor as your newly created 'Sublime Text Launcher For Unity' application with the usual arguments:

    Screenshot 2020-05-21 at 11.26.59.png

    That's it. Every time you open a script in Unity, it will send it to your Sublime Text Launcher automator app and be handled the right way to only open it in a single instance of Sublime. You shouldn't notice any weirdness, things should just work.

    I'm obviously not going to run support on this but it does work for me on Mac OS X 10.15.4 :)

    - Mel
     
    Last edited: May 21, 2020
    UNSH likes this.
  12. Sailendu

    Sailendu

    Joined:
    Jul 23, 2009
    Posts:
    194
    @melgeorgiou thanks a lot for posting this solution, I was facing the same issue, now it's working.
     
  13. melgeorgiou

    melgeorgiou

    Joined:
    Nov 3, 2012
    Posts:
    677
    UNSH likes this.
  14. UNSH

    UNSH

    Joined:
    Jul 2, 2012
    Posts:
    48
    Other solution set unity preferences to open file by extension and set the default extension in finder (cmd+i) for .cs to Sublime.
     
  15. drpelz

    drpelz

    Joined:
    Dec 7, 2017
    Posts:
    58
    Just wanted to say thank you for this great post! It works like a charm on Mac OS X 11.0.1 Big Sur!:)
     
    melgeorgiou likes this.
  16. nicmarxp

    nicmarxp

    Joined:
    Dec 3, 2017
    Posts:
    374
    I can't stress enough, use an IDE like Visual Studio or Rider. It will save you so much time and headaches, I'm using Rider which is excellent. First I thought it would be cpu intensive, but I'm super happy with it. Maybe sublime has similar extensions now, but I can't imagine how I worked with plain sublime 3 years ago :)
     
unityunity