Search Unity

VS code - files not opened from Unity

Discussion in 'Code Editors & IDEs' started by Fr2, May 30, 2019.

  1. Fr2

    Fr2

    Joined:
    Jan 19, 2013
    Posts:
    39
    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
  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:
    39
    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:
    45
    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:
    45
    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:
    45
    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:
    45
    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. KiddUniverse

    KiddUniverse

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

    mattparkins

    Joined:
    Apr 1, 2014
    Posts:
    31
    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
    KiddUniverse likes this.
  14. jasonatkaruna

    jasonatkaruna

    Joined:
    Feb 26, 2019
    Posts:
    64
    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:
    39
    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:
    64
    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:
    39
    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:
    64
    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:
    39
    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:
    471
    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.
     
  24. Kerrjgan

    Kerrjgan

    Joined:
    May 30, 2016
    Posts:
    10
    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:
    471
    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:
    6

    This helped me, thanks a million!
     
  27. Incode

    Incode

    Joined:
    Apr 5, 2015
    Posts:
    78
    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. KiddUniverse

    KiddUniverse

    Joined:
    Oct 13, 2016
    Posts:
    115
    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:
    134
    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. KiddUniverse

    KiddUniverse

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

     
  31. Voronoi

    Voronoi

    Joined:
    Jul 2, 2012
    Posts:
    590
    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:
    64
    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:
    2
    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:
    41
    does it happen after a restart of Unity?
     
  35. herb_nice

    herb_nice

    Joined:
    May 4, 2017
    Posts:
    170
    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:
    170
    ....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:
    170
    ... 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:
    29
    Have the same problem on Windows and 2019.2.8f1
     
  39. Shizola

    Shizola

    Joined:
    Jun 29, 2014
    Posts:
    476
    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:
    111
  41. KiddUniverse

    KiddUniverse

    Joined:
    Oct 13, 2016
    Posts:
    115
    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:
    170
    that did not work for me.
     
  43. Adrian

    Adrian

    Joined:
    Apr 5, 2008
    Posts:
    1,066
    I also got the MissingMethodException error on macOS with Unity 2019.2.9f1 using VSCode.

    But I only had it in one project, another one was working fine. Comparing the two, I noticed I had removed the Rider IDE package. I added it back and now VSCode works again.

    Note that Rider Editor package 1.1.1 has an invalid dependency on the Test Framework 1.1.1, which is not verified for 2019.2 and won't be installed, leading to compilation errors. Install the Rider Editor package 1.1.0 instead.

    This transition of editor support to external packages has been really painful. The basic functionality of opening scripts breaking repeatedly, bugs being fixed only very slowly and requiring tedious troubleshooting and workarounds. Unity's testing of these changes has been really lacking.
     
  44. Aethesir

    Aethesir

    Joined:
    Sep 25, 2017
    Posts:
    1
    I had the same problem, could not open files from Unity, but from within Windows.
    The only thing that helped me was to uninstall Visual Studio Code and install the Insiders build instead:
    https://code.visualstudio.com/insiders/
     
  45. studentvz

    studentvz

    Joined:
    Dec 14, 2014
    Posts:
    149
    I have the same problem, out of nowhere, now I can open VS Code from Unity, but IntelliSense and Snippets are not working.

    The reference assemblies for .NETFramework,Version=v4.7.1 were not found. To resolve this, install the Developer Pack (SDK/Targeting Pack) for this framework version or retarget your application. You can download .NET Framework Developer Packs at https://aka.ms/msbuild/developerpacks

    I have installed the latest .NET Framework Developer Packs.
     
    Last edited: Oct 28, 2019
  46. BParisi-CaInc

    BParisi-CaInc

    Joined:
    Sep 26, 2019
    Posts:
    1
    This worked for me. But first I had to go into the "Details" tab in my task manager and end all the existing VS Code processes.
     
    glitchers likes this.
  47. herb_nice

    herb_nice

    Joined:
    May 4, 2017
    Posts:
    170
    vscode updated itself the other day and this problem stopped happening. i am now on vscode 1.39.2 and things are back to normal.
     
  48. glitchers

    glitchers

    Joined:
    Apr 29, 2014
    Posts:
    64
    This one worked for me. Thank you.
     
  49. Incode

    Incode

    Joined:
    Apr 5, 2015
    Posts:
    78
    It looks like this is fixed in package 1.1.3.
     
    eits likes this.
  50. alexisdavidson

    alexisdavidson

    Joined:
    Apr 28, 2015
    Posts:
    29
    Can't seem to be able to download 1.1.3 from the Package Manager. For me, the 1.1.2 is the latest version available