VS code - files not opened from Unity

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!

5 Likes

I have the same problem! It’s driving me crazy. Any solution for this yet?

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!

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.

1 Like

I was able to get this working by following the instructions here Unity - vscode-docs

VS Code is so much better!!

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.

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.

1 Like

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.

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

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.

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??!?!?!?!!?

Is there a fix for this yet? this started happening to me this week.

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.

1 Like

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.

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.

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.

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?

1 Like

I’ve tried making a copy. I’ll try to make a new project and copy the assets over.

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).

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.