Can't get VSCode to work properly with Unity

I’ve been trying to get Intellisense to work, but I don’t get any relevant autocompletion like other people I’ve seen here.

I’ve followed the instructions on this post: VSCode for Linux not opening projects correctly

This is what I’m getting, compared to the screenshots in that thread. imgur-2018_06_28-14:49:16 - Imgur

Not sure what could be happening. The C# extension is installed, and mono too. I’ve followed the steps indicated here too: Visual Studio Code and Unity but I can’t get it to work properly.

Here’s how I have vscode set up from Unity: imgur-2018_06_28-14:54:20 - Imgur

I hope anyone here could have a lead regarding what I’m missing.

1 Like

I’ve found that the issue might be that Unity isn’t generating .sln files, which VSCode seem to need in order for the imports to work. Any idea about why those files aren’t being generated?

2 Likes

Your dead on with the issue being Unity not creating the .sln files. I’ve been having the exact same issue as well since updating Unity.

I’ve found a workaround to generate the .sln files.

  • go to Edit → Preferences, then select the External tools tab
  • Ignore all advice given on other threads where you create an alias or a symbolic link to add custom arguments. Instead of that, in the External Script Editor field, select /usr/bin/code
  • If you selected the correct executable, there shouldn’t be any External Script Editor Args field.
  • if you try to open any script from unity now, it will still won’t work. Code files won’t be generated, and only the script will be opened in code, instead of the folder. Don’t worry.
  • Go to Assets → Open C# Project. Now code will open the project folder, the .stl files and other meaningful files will be generated (like the .vscode folder), and Intellisense will work properly.

Let me know if it works for you too.

52 Likes

I think this is a bug with Unity 2018.2 (at least, that is when my troubles started) … As you already pointed out, Unity no longer creates the .sln file. In my project, the .sln file is there but is no longer updated.

At least for now, following your approach by going Assets → Open C# Project works. Thank you :slight_smile:

8 Likes

This issue is that Unity Editor expects the file used to launch VSCode to have a specific name. It seems that unity will only trigger the .sln/.csproj generation routine if the filename matches a hard-coded value.

Specifically, creating a symlink named “code” that opens VSCode fixed this issue for me. The normal binary was named “visual-studio-code”, which Unity didn’t recognize as VSCode.

Unity devs may want to consider a more sophisticated method of determining whether the selected external editor is VSCode, VS, etc.

8 Likes

https://feedback.unity3d.com/suggestions/option-to-let-user-generate-solution-and-project-files

Thank you guys for the workaround, I was using VSCode Insiders which has a different executable name and wouldn’t make Unity generate project files. Please upvote that suggestion so that we can have a decent behaviour with any code editor!

2 Likes

Didn’t work for me maybe because I’m using Arch and getting VS code from the AUR and the executable is code-oss. In the end I fixed it by using the symbolic link method:

sudo ln -s /usr/bin/code-oss /usr/bin/code

Then followed your steps and got it working.

1 Like

Make sure project name doesnt have a space in it, messes with vs code

4 Likes

I don’t have any External Script Editor field. Am I doing something wrong?
I’m using 2018.3.0f2

Look at the top of the menu items…

For anybody this still isn’t working for, download and install the latest version of Mono and re-open (Use ‘Open C# Project’)

https://www.mono-project.com/download/stable/

8 Likes

oh, thank you!! i love you

This worked for me too. Ty Sam

I just had to:
UnityPreferencesExternal ToolsExternal Script EditorBrowse → Manually select VSCode

I think the problem on my machine was two versions of VSCode fighting for Unity’s love.

4 Likes

I solved this problem by trying this solution-

  • Open Visual Studio Community(if you don’t have, install it)

  • Go to your unity Project folder

  • There will be a file like – ‘YOUR_PROJECT_NAME.sln’

  • Double click that file and choose to open in Visual Studio Community

  • It will load your solution file

  • Then it will show you a window saying unity is target to .net vsxxx and this is not installed in your computer. With 2 options
    a. Download that .net framework version
    b. change target .net framework version

  • Download the missing .net framework version by clicking the option

  • Restart Unity and vscode

I solved this problem by trying this solution-

  • Open Visual Studio Community(if you don’t have, install it)

  • Go to your unity Project folder

  • There will be a file like – ‘YOUR_PROJECT_NAME.sln’

  • Double click that file and choose to open in Visual Studio Community

  • It will load your solution file

  • Then it will show you a window saying unity is target to .net vsxxx and this is not installed in your computer. With 2 options
    a. Download that .net framework version
    b. change target .net framework version

  • Download the missing .net framework version by clicking the option

  • Restart Unity and vscode

1 Like

Installing Mono 6 preview fixed this for me. Was a real headache before that…

3 Likes

I create empty project in 2019.2.0b1.
I set to External Script Editor the symlink sudo ln -s /snap/bin/code-insiders /usr/bin/code
Unity field “Script Editor” changed from file name to “Visual Studio Code”
Unity field “Script Editor Args” changed to "$(ProjectPath)" -g "$(File)":$(Line):$(Column)
I click Open C# Project, and get errors like:

Usage: open [OPTIONS] -- command
(Filename: Library/PackageCache/com.unity.ide.vscode@1.0.4/Editor/VSCodeScriptEditor.cs Line: 147)

UPDATE.
Create symbolik link is worng, it must be an alias
sudo snap alias code-insiders code

Not working with vscode from snap
Not working with vscode insiders from snap or apt
Unity expect only /usr/bin/code for creating sln and csproj

But problem with arguments still happens, Unity tryes launch openvt not vscode.
Full log https://pastebin.com/uhrxQahv

2 Likes

Thanks Mate!
Started with unity 2 weeks ago. On windows it’s working fine, but on linux I have very big issues to make it run and there is very few information, because everything that you find online is already outdated and doesn’t work.

I have the same issues. No version of VSC works for me. C# Extension/omnisharp is not recognizing my files as .cs and when I installed another extension to create a cs file, it gave me an error that .json files could not be found. So I’m currently downloading the previos version. Hopefully I can make it work there.

Thanks for reporting