Search Unity

  1. Unity 2019.2 is now released.
    Dismiss Notice

Can't get VSCode to work properly with Unity

Discussion in 'Linux Editor' started by Kurolox, Jun 28, 2018.

  1. Kurolox

    Kurolox

    Joined:
    Aug 13, 2015
    Posts:
    4
    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: https://forum.unity.com/threads/vscode-for-linux-not-opening-projects-correctly.527924/

    This is what I'm getting, compared to the screenshots in that thread. https://i.imgur.com/bDtoKzn.png

    Not sure what could be happening. The C# extension is installed, and mono too. I've followed the steps indicated here too: https://code.visualstudio.com/docs/other/unity but I can't get it to work properly.

    Here's how I have vscode set up from Unity: https://i.imgur.com/ROBbCEl.png

    I hope anyone here could have a lead regarding what I'm missing.
     
    b1oki likes this.
  2. Kurolox

    Kurolox

    Joined:
    Aug 13, 2015
    Posts:
    4
    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?
     
    b1oki likes this.
  3. DGLWilkins

    DGLWilkins

    Joined:
    Sep 25, 2012
    Posts:
    7
    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.
     
    Last edited: Jun 30, 2018
  4. Kurolox

    Kurolox

    Joined:
    Aug 13, 2015
    Posts:
    4
    I've found a workaround to generate the .sln files.

    1. go to Edit -> Preferences, then select the External tools tab
    2. 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
    3. If you selected the correct executable, there shouldn't be any External Script Editor Args field.
    4. 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.
    5. 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.
     
    Kayalous, codeedward, b1oki and 4 others like this.
  5. DevinDazzlr

    DevinDazzlr

    Joined:
    Dec 3, 2013
    Posts:
    2
    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 :)
     
    vipjiaqi and b1oki like this.
  6. unityoracle

    unityoracle

    Joined:
    Jul 3, 2018
    Posts:
    12
    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.
     
    storytellerjonas and Novack like this.
  7. LitchiSzu

    LitchiSzu

    Joined:
    May 14, 2016
    Posts:
    17
  8. DGLWilkins

    DGLWilkins

    Joined:
    Sep 25, 2012
    Posts:
    7
    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.
     
  9. marchinram

    marchinram

    Joined:
    Jan 28, 2014
    Posts:
    5
    Make sure project name doesnt have a space in it, messes with vs code
     
    The7thNoodle likes this.
  10. Justice0Juic3

    Justice0Juic3

    Joined:
    Apr 29, 2013
    Posts:
    175
    I don't have any External Script Editor field. Am I doing something wrong?
    I'm using 2018.3.0f2
     
  11. radixtrator

    radixtrator

    Joined:
    Jan 6, 2019
    Posts:
    1
    Look at the top of the menu items...
     
  12. SamFZGames

    SamFZGames

    Joined:
    Mar 2, 2014
    Posts:
    5
    M4RCIN and jacobgmartin like this.
  13. myroomtm

    myroomtm

    Joined:
    Nov 15, 2012
    Posts:
    7
    oh, thank you!! i love you
     
  14. uweenukr

    uweenukr

    Joined:
    Jan 17, 2011
    Posts:
    53
    This worked for me too. Ty Sam
     
  15. tmendez

    tmendez

    Joined:
    Oct 12, 2015
    Posts:
    35
    I just had to:
    Unity -> Preferences -> External Tools -> External Script Editor -> Browse -> Manually select VSCode

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

    rohitvishwakarma1819

    Joined:
    Feb 15, 2018
    Posts:
    5
    I solved this problem by trying this solution-

    1. Open Visual Studio Community(if you don't have, install it)

    2. Go to your unity Project folder

    3. There will be a file like -- 'YOUR_PROJECT_NAME.sln'

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

    5. It will load your solution file

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

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

    8. Restart Unity and vscode
     
  17. rohitvishwakarma1819

    rohitvishwakarma1819

    Joined:
    Feb 15, 2018
    Posts:
    5

    I solved this problem by trying this solution-

    1. Open Visual Studio Community(if you don't have, install it)

    2. Go to your unity Project folder

    3. There will be a file like -- 'YOUR_PROJECT_NAME.sln'

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

    5. It will load your solution file

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

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

    8. Restart Unity and vscode
     
  18. Kjaka

    Kjaka

    Joined:
    Dec 8, 2015
    Posts:
    9
    Installing Mono 6 preview fixed this for me. Was a real headache before that..
     
    PixelJ likes this.
  19. b1oki

    b1oki

    Joined:
    Dec 21, 2018
    Posts:
    7
    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:
    Code (csharp):
    1. Usage: open [OPTIONS] -- command
    2. (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
     
    Last edited: May 11, 2019
    ThrowingShade282 and HZ51 like this.
  20. SputnikHQ

    SputnikHQ

    Joined:
    May 14, 2019
    Posts:
    1
    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
     
  21. JJ_FX

    JJ_FX

    Joined:
    Mar 19, 2015
    Posts:
    51
    Oh yeah, this helps! Intellisense is working for me after installation.

    But after changing to vscode with "$(ProjectPath)" -g "$(File)":$(Line):$(Column) now every time I open .cs file VSCode opens up two sessions:
    one "Test.sc - Visual Studio Code" (intellisense not working) and
    second "Test.sc - MyProject - Visual Studio Code" (intellisense working) :) haha

    I can just close the one that doesnt work, but a bit annoying. Any1?
     
  22. Z0hann

    Z0hann

    Joined:
    Nov 1, 2014
    Posts:
    1
    Very simple solution what worked for me:
    1. Delete any .sln, .csproj, .unityproj files from the project's root folder
    2. Go to Assets -> Open C# project
    3. ???
    4. Profit.
     
  23. Cryterion

    Cryterion

    Joined:
    Jul 15, 2012
    Posts:
    1
    Thank you so much! This fixed it for me after looking for a solution for hours.
     
  24. Irina-uk

    Irina-uk

    Joined:
    Feb 14, 2014
    Posts:
    19
    Please tell me how I can’t configure Visual Studio Code in Unity 2019.2. It works great in Unity 2019.1. What, did I do wrong? Unity 2019.2 - no support VSC ?

    Unity 2019.2 - Bad Work VSC
    upload_2019-8-3_19-0-19.png


    Unity 2019.1 - Good Work VSC
    upload_2019-8-3_18-58-28.png
     

    Attached Files:

    Conferno likes this.
  25. ilyusha71

    ilyusha71

    Joined:
    Jun 21, 2016
    Posts:
    1
    sad
    same problem
     
  26. Irina-uk

    Irina-uk

    Joined:
    Feb 14, 2014
    Posts:
    19
    Unity 2019.2 - works great - Visual Studio 2019 (1 GB system memory). :)macOS Mojave 10.14.5
    VSC - 100 MB system memory - It works incorrectly for me, not like I'm used to it. :(
     
  27. moncastro

    moncastro

    Joined:
    Aug 13, 2015
    Posts:
    4
    Eyap likes this.
  28. Conferno

    Conferno

    Joined:
    Feb 27, 2014
    Posts:
    28
    Yeah have the same issues with Unity 2019.2 and VSC...
     
  29. PixelJ

    PixelJ

    Unity Technologies

    Joined:
    Nov 1, 2018
    Posts:
    114
    Vote for that issue. If the mac bug is fixed it will likely fix the linux bug.
     
    Eyap likes this.
  30. Its4u

    Its4u

    Joined:
    Oct 11, 2013
    Posts:
    13
    I got a temporary solution.
    Check file
    VSCodeScriptEditor.cs
    in folder
    Packages/Visual Studio Code/Editor
    Replace this line
    Code (CSharp):
    1. Arguments = $"\"{GetDefaultApp}\" --args {arguments}",
    to
    Code (CSharp):
    1. Arguments = $"-n \"{GetDefaultApp}\" --args {arguments}",
    I have to do that everytime I open project. Still annoy but better.