Search Unity

VS code - files not opened from Unity

Discussion in 'External Tools' started by Fr2, May 30, 2019.

  1. Fr2

    Fr2

    Joined:
    Jan 19, 2013
    Posts:
    22
    Unity version 2019.2.0b2
    VS Code version 1.34.0
    Using a mac 10.14

    When double clicking a .cs file in the Unity editor, VS launches and the .cs file opens. All good. However, if I try to open another .cs file from the Unity editor (same project), then the VS Code application is shown, but the file does not open. If I quit VS Code and try opening the file again from Unity, then the file opens OK.

    I've tried to resolve this by modifying the External Script Editor Args "$(ProjectPath)" -g "$(File)":$(Line):$(Column) in Unity, and also trying to edit the VSCodeScriptEditor's OpenOSX() function - neither have worked.
    I can open files from terminal using the command line arguments OK.

    Have verified that files open correctly using Unity 2018.3.8f1

    Driving me mad, any suggestions would be appreciated!
     
    Last edited: May 30, 2019
    Anthony0506, cplover, faust and 2 others like this.
  2. Forkeseal

    Forkeseal

    Joined:
    Feb 5, 2019
    Posts:
    4
    I have the same problem! It's driving me crazy. Any solution for this yet?
     
  3. Fr2

    Fr2

    Joined:
    Jan 19, 2013
    Posts:
    22
    Sorry no. I switched to Visual Studio as an interim measure, hoping a future update would fix the problem. I've had to park my unity project for a couple of months, so will revisit this problem soon. Really annoying!
     
  4. Paul_H23

    Paul_H23

    Joined:
    Jun 19, 2019
    Posts:
    14
    Same problem here, driving me nuts too, I hate Visual Studio Community, it feels so clunky compared to Code, any fix/workaround would be massively appreciated.
     
    mikapote likes this.
  5. Forkeseal

    Forkeseal

    Joined:
    Feb 5, 2019
    Posts:
    4
  6. Paul_H23

    Paul_H23

    Joined:
    Jun 19, 2019
    Posts:
    14
    That's what I originally followed, and it worked fine, right up until I updated to the latest 2019 version of Unity and then it all went pear shaped.
     
  7. Forkeseal

    Forkeseal

    Joined:
    Feb 5, 2019
    Posts:
    4
    After the update I had to remove the VSCode.cs file in Assets/Plugins/Editor and add it again. Worked fine after re-adding it.
     
    Paul_H23 likes this.
  8. Paul_H23

    Paul_H23

    Joined:
    Jun 19, 2019
    Posts:
    14
    Thanks, that seems to work for now. It's a shame that the native Unity support of VSCode doesn't work without needing a third party plugin, but I'll take anything right now.
     
  9. StarSmasher

    StarSmasher

    Joined:
    Aug 28, 2019
    Posts:
    2
    I'm experiencing the same problems as described above.
    I can confirm that Visual Studio Code works fine for me with Unity 2018.4.7f1
    And I can confirm that Visual Studio Code does not work for me with Unity 2019.2.4f1
     
  10. StarSmasher

    StarSmasher

    Joined:
    Aug 28, 2019
    Posts:
    2
    Also, it looks like "External Script Editor Args" in Edit -> Preferences -> External Tools seems to be new to Unity 2019. I don't see it in Unity 2018. Deleting the "External Script Editor Args" args at least allows VIsual Studio Code to open, but without the relevant file.
     
  11. Paul_H23

    Paul_H23

    Joined:
    Jun 19, 2019
    Posts:
    14
    Aaarrggghhhh I give up!!! Used VSCode for a while based on the advice above, then that became too slow to update when I make a change, compile times through the roof. So switched back to VS Community, now that doesn't work either. Is there any combination of Unity and IDE that actually works??!?!?!?!!?
     
  12. Anthony0506

    Anthony0506

    Joined:
    Oct 13, 2016
    Posts:
    74
    Is there a fix for this yet? this started happening to me this week.
     
  13. mattparkins

    mattparkins

    Joined:
    Apr 1, 2014
    Posts:
    30
    This is happening to me too on Mac. It's v frustrating!

    Update: For now I've gone back to Script Inspector 3 (which is very good also, and quick, but no debugging). Would love this one sorted.
     
    Last edited: Sep 12, 2019
    Anthony0506 likes this.
  14. jasonatkaruna

    jasonatkaruna

    Joined:
    Feb 26, 2019
    Posts:
    8
    Also unable to open VS Code. My problem extends to not just trying to open VS Code from the Unity Editor. I'm unable to open my project's folder from VS Code. Trying "Open with code" or selecting the folder from within vscode does nothing.


    EDIT:
    It looks like it works in a brand new project, so I'm not sure why my current project is preventing vscode from opening. Also, other text editors don't seem to be able to open.
     
    Last edited: Sep 13, 2019
  15. Fr2

    Fr2

    Joined:
    Jan 19, 2013
    Posts:
    22
    Just tried these instructions, and they do seem to work. Upgrading Unity to 2019.2.4f1 produced some script errors which broke the VSCode integration, but after fixing the errors and re-adding the VSCode.cs file it's working again.
     
  16. jasonatkaruna

    jasonatkaruna

    Joined:
    Feb 26, 2019
    Posts:
    8
    I'm convinced my particular issue is with a unity lock on my project going haywire, this could explain why I can't open the project folder in other editors.

    Does anyone have any debugging suggestions for fixing this particular issue? I've skimmed through vscode logs and Unity logs, and although I've probably missed something important, I didn't see any clues.
     
  17. Fr2

    Fr2

    Joined:
    Jan 19, 2013
    Posts:
    22
    That's a tough one. Assuming it's not related to source control locks or permissions, have you tried making a copy of your project, or creating a new project and copying your assets over?
     
    jasonatkaruna likes this.
  18. jasonatkaruna

    jasonatkaruna

    Joined:
    Feb 26, 2019
    Posts:
    8
    I've tried making a copy. I'll try to make a new project and copy the assets over.
     
  19. Owers

    Owers

    Joined:
    Jul 7, 2012
    Posts:
    37
    For what it's worth, my solution to this problem was to configure Windows to open .cs files in Visual Studio Code by default, and then change the 'External Script Editor' setting to 'Open by File Extension' in Unity preferences. Scripts will open from Unity using Visual Studio Code, but it won't open the C# project or use intellisense. To fix that, I then go to 'File > Open Folder...' in Visual Studio Code and open the Unity project folder. If Visual Studio Code is closed, then I have to repeat the process.

    It's a lousy solution, but it'll work for me until it gets officially resolved (hopefully).
     
  20. octav1an

    octav1an

    Joined:
    Jun 21, 2017
    Posts:
    1
    I have the same issue on Unity 2019.2.4. Most of the times VS Code won't open the cs files from Unity and does not even want to open Unity project when I go to File->Open Folder, nothing happens. However from time to time, if the planets are aligned, it seems to work correctly. That is frustrating. I have also tried VSCodium, at first it was fine, now it too doesn't work.
     
  21. Forkeseal

    Forkeseal

    Joined:
    Feb 5, 2019
    Posts:
    4
    I have just updated to Unity 2019.2.5f1 and VSCode now works perfectly!
     
  22. Amir-Ward

    Amir-Ward

    Joined:
    Jan 26, 2015
    Posts:
    30
    I'm on 2019.2.5f1 and it worked for a bit but now it won't even attempt to load VSCode at all.
     
  23. Muckel

    Muckel

    Joined:
    Mar 26, 2009
    Posts:
    436
    hello,
    well all your problems comes while you did not update the VSCode plugin in Packetmanager...
    Do it and no need for other stuff... the VSCode plugin is deprecated and not needed if you update via Packet manager.. best delete this old VSCode plugin from Editor folder... it works super without...

    looks like Unity is focussing more on Windows... hence the late fixes for iOS and Mac...
    i'm using UE4 on my Mac too... once i get my stuff working in UE i say goodby to Unity...
    i'm user from Version 1 where it was Mac only... i'm sooooo disappointed by Unity...
    they even don't do good beta testing anymore.... let the User do it its much cheaper ;-)
    look @ the last version of 2019.2 ... it's so buggy and output to Android & iOS too...
    since we don't get money for the time we spent searching bugs or discovering bug and take the time to document them... No Thank you nothing.... and maybe it get fixed mayyyyyyybeeee
    Unity had much better times as you see here in the forum....
    it's rare if you get a answer to your questions... no Unity peeps are here in the forum....
    if you have a problem... support doesn't exist... you can also not mail the problem...

    and than they ask our community what's up... why you don't submit games and apps for our campaigns ...
    loooool because UNITY3D doesn't care anymore what's up under the developer...
    Unity3d is now too big... they lost focus on quality and functionality ...
    they care now more for high end games that make 5% of the Unity user... only for marketing LOL
    they should better do there homework and focus what the mass needs ...
    a stable working editor on all platforms that are supported...!

    @ Unity3d
    Do your homework we pay you for this!!!
    and focus on quality not on features only 1-5% of the user want !!!

    M.
     
    tng2903 and sier_ua like this.
  24. Kerrjgan

    Kerrjgan

    Joined:
    May 30, 2016
    Posts:
    6
    I've updated my project from 2019.1 -> 20192.6f1 and can no longer open the project from the editor (by clicking the scripts). When I open a script it open's it singularly. I have the latest VSCode package from the package manager and it's set in the preferences (external tools) but still no luck. Using Windows 10

    the guy above me is an idiot
     
  25. Muckel

    Muckel

    Joined:
    Mar 26, 2009
    Posts:
    436
    and you a noob who has no idea...
    just wonder if you have a license or use a illegal version...
     
    Last edited: Sep 28, 2019
  26. sier_ua

    sier_ua

    Joined:
    Jan 19, 2017
    Posts:
    5

    This helped me, thanks a million!
     
  27. benjamminlaner

    benjamminlaner

    Joined:
    Apr 5, 2015
    Posts:
    11
    Also having this issue on 2019.2.6f1 using the 1.1.2 VS code package. I've tried opening the project, opening via file extension, deleting the vs code settings, reinstalling vs code, and a few other things to no effect. Currently trying to nuke my library in case there's some weird cached state issue.

    There is currently an open ticket for the 1.1.0 package:
    https://issuetracker.unity3d.com/is...external-script-editor-is-set-to-code-dot-exe

    Hopefully we'll hear more about this soon.
     
  28. Anthony0506

    Anthony0506

    Joined:
    Oct 13, 2016
    Posts:
    74
    as annoying as it is, the easiest solution for right now if you want to use code is to open code before you start unity. now, when you click on any script inside of unity, it will open in code as usual. just put your shortcuts right next to each other. i'm sure they will make a fix eventually.
     
  29. interpol_kun

    interpol_kun

    Joined:
    Jul 28, 2016
    Posts:
    76
    Can't open a single file via VSCode on Unity 2019.2.6 (Windows 10). Have to switch to Visual Studio for now. Updating the packages and other stuff mentioned in the thread didn't help.

    Can't believe that could be a problem with a stable version (even after a few updates).
     
    Shizola and herb_nice like this.
  30. Anthony0506

    Anthony0506

    Joined:
    Oct 13, 2016
    Posts:
    74
    heres the fix for now.

     
  31. Voronoi

    Voronoi

    Joined:
    Jul 2, 2012
    Posts:
    271
    This was driving me crazy on a Mac!

    Edit: NOT a solution: go to the Unity>Preferences>External Tools>External Script Editor and set it to 'Open by file extension'. Also checked is Generate all .csproj files.

    Now, make sure your Mac is set to open .cs files using Visual Studio Code and it should work, opening the specific file when double-clicking in the Unity Editor.

    Edit: The above works, sort of... The file opens, but now I get this error in the Editor:
    Code (CSharp):
    1. MissingMethodException: Attempted to access a missing method.
    2. Unity.CodeEditor.CodeEditor.OSOpenFile (System.String appPath, System.String arguments) (at /Users/builduser/buildslave/unity/build/Editor/Mono/CodeEditor/CodeEditor.cs:157)
    3. UnityEditor.DefaultExternalCodeEditor.OpenProject (System.String path, System.Int32 line, System.Int32 column) (at /Users/builduser/buildslave/unity/build/Editor/Mono/CodeEditor/DefaultExternalCodeEditor.cs:117)
    4. Unity.CodeEditor.CodeEditor.OpenProject (System.String path, System.Int32 line, System.Int32 column) (at /Users/builduser/buildslave/unity/build/Editor/Mono/CodeEditor/CodeEditor.cs:31)
     
    Last edited: Sep 30, 2019
  32. jasonatkaruna

    jasonatkaruna

    Joined:
    Feb 26, 2019
    Posts:
    8
    I'm getting a similar error, but mine seems to be related to a faulty lock file. This is just a guess on my part. My magical, hacky workaround anytime it won't open vscode has been to:

    1. Restart computer.
    2. Run `git clean -fxd` since I'm in a git repo (should delete any ignored files/clear library cache)
    3. Reopen project and wait for unity to rebuild everything.

    One thing to note is that I'm on windows fast ring (18990) --so perhaps the folder permissions are bugged from my windows update.
     
  33. Lighter02

    Lighter02

    Joined:
    Oct 24, 2015
    Posts:
    1
    I encountered this issue a few days ago after upgrading to Unity 2019.2.6f1 and just fixed this by removing the "Visual Studio Code Editor" package from the package manager and then reinstalling it.

    It doesn't seem to be having any issues opening different files from inside Unity anymore, so hopefully this solution works for others.

    Edit - This is on a Mac, but hopefully this extends to other platforms as well
     
  34. tng2903

    tng2903

    Joined:
    Apr 8, 2013
    Posts:
    33
    does it happen after a restart of Unity?
     
  35. herb_nice

    herb_nice

    Joined:
    May 4, 2017
    Posts:
    153
    visual studio code 1.38.1 will no longer open my main project from unity 2019.2.8f1. it worked earlier today. but now visual studio code simply rejects it. visual studio code WILL open a different project that i saved yesterday....

    on the borked project, clicking on links from unity to the source or trying to manually open the project in vs code does not work any more. rebooting/closing/removing/reinstalling vs code package in unity does not help. amazing.
     
    Last edited: Oct 9, 2019
  36. herb_nice

    herb_nice

    Joined:
    May 4, 2017
    Posts:
    153
    ....and it randomly started working again today. something is fishy but at least it is working again.
     
  37. herb_nice

    herb_nice

    Joined:
    May 4, 2017
    Posts:
    153
    ... and it randomly stopped working again today. i think it could be visual studio code being weird, as i diffed the slns and nothing looked visibly wonky
     
  38. alexisdavidson

    alexisdavidson

    Joined:
    Apr 28, 2015
    Posts:
    13
    Have the same problem on Windows and 2019.2.8f1
     
  39. Shizola

    Shizola

    Joined:
    Jun 29, 2014
    Posts:
    190
    This is another one of those things that I can't believe Unity doesn't fix or at least acknowledge immediately. code seems so much better suited for unity than vs, I don't get it.
     
  40. Domas_L

    Domas_L

    Unity Technologies

    Joined:
    Nov 27, 2018
    Posts:
    91
  41. Anthony0506

    Anthony0506

    Joined:
    Oct 13, 2016
    Posts:
    74
    instead of using the EXE file, use the CMD file in the bin folder and then its back to working.
     
  42. herb_nice

    herb_nice

    Joined:
    May 4, 2017
    Posts:
    153
    that did not work for me.