Search Unity

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.
     
  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
    liderako likes this.
  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
     
    Wootato and The7thNoodle like 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:
    6
    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:
    6

    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:
    10
    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:
    57
    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:
    32
    Yeah have the same issues with Unity 2019.2 and VSC...
     
    samf1111 likes this.
  29. PixelJ

    PixelJ

    Unity Technologies

    Joined:
    Nov 1, 2018
    Posts:
    134
    Vote for that issue. If the mac bug is fixed it will likely fix the linux bug.
     
    samf1111 and Eyap like 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.
     
    CanisLupus, riecre, xahei and 8 others like this.
  31. Adrian

    Adrian

    Joined:
    Apr 5, 2008
    Posts:
    371
    Really annoying.

    You can remove the "Visual Studio Code Editor" package and then opening files will work again. But opening the project won't and the csproj files will only update when you reopen the project.

    You can make the change above permanent per project by copying the «com.unity.ide.vscode@1.0.7» folder from «Library/PackageCache» to «Packages», remove the «@1.0.7» and do the change there. This copy will override the package and the change will stick.
     
    antpaw likes this.
  32. khushalkhan

    khushalkhan

    Joined:
    Aug 6, 2016
    Posts:
    9
    Its annoying but here is something you can do,
    First of all update Visual Studio Code Editor package to 1.1.0 from package manager, then goto Unity menu --> Preferences --> External Tools and Enable Generate all .csproj files checkbox, Quit vscode, and . in unity goto Assets Menu --> Open c# Project
     
    Last edited: Aug 21, 2019
  33. Adrian

    Adrian

    Joined:
    Apr 5, 2008
    Posts:
    371
    Still does not work for me. Only opens the project and file if VSCode is closed, otherwise just focuses it without doing anything. The editing of VSCodeScriptEditor.cs above is still required.
     
    khushalkhan likes this.
  34. khushalkhan

    khushalkhan

    Joined:
    Aug 6, 2016
    Posts:
    9
    Adrain have you tried updating mono as mention in above comments?
     
  35. Adrian

    Adrian

    Joined:
    Apr 5, 2008
    Posts:
    371
    I'm updating mono regularly. Just updated to the latest version, still doesn't work.

    I also fail to see how mono would be involved in this? Unity bundles its own mono and on VSCode's side it's Electron and JavaScript, mono is only used by OmniSharp, which shouldn't get involved with opening files.
     
  36. khushalkhan

    khushalkhan

    Joined:
    Aug 6, 2016
    Posts:
    9
    Ok instead of adding line to code file rename VSCode app to "-n Visual Studio Code" along with quotes as long unity does not fix the error its a valid solution for me. Can't add line of code to every new project.
     
  37. Conferno

    Conferno

    Joined:
    Feb 27, 2014
    Posts:
    32
    The Unity team just broke more this stuff on latest version of Unity editor 2019.2.2f1 - now, when you chose in properties the Visual studio Code, after double clicking on scene file in Project tab, it opens the .unity file inside the Visual Studio Code... LOL.
     
    torboot11 likes this.
  38. khushalkhan

    khushalkhan

    Joined:
    Aug 6, 2016
    Posts:
    9
    I downgraded to 2019,1
     
  39. Minicades-Mobile

    Minicades-Mobile

    Joined:
    Sep 15, 2012
    Posts:
    19
    looks like a fix is still needed on unity's end (package update?)
     
  40. antpaw

    antpaw

    Joined:
    Oct 25, 2016
    Posts:
    7
  41. xahei

    xahei

    Joined:
    Sep 22, 2014
    Posts:
    8
    Same issue here...
    Thanks, your solution works! This drove me nuts all day o_O
    Is there a ticket for this issue? I see antpaw's link, but it's not the same issue.
    For me, clicking on any .cs file opens VSCode, but without any link to the actual file / project.
     
  42. Muckel

    Muckel

    Joined:
    Mar 26, 2009
    Posts:
    436
    Windows > PackageManager > update VS CODE to 1.1.2 = all is working as before no change for Args... or settings!!!
    Just update the outdated plugin!
    i wish there was a auto update function for packages that get incompatible after upgrade...

    also the fxxk Unity HUB.... what a messy software...
    show's false HD Size information on Mac OS X...
    so have over 100 GB free and Hub tells me no space available to install
    i really wonder who is working @ Unity3d ... looks like a few noob's who code the hub...
    can not understand the sense ... another memory eating app for what???

    @ UNITY3D .. you don't make it easy for the paying community ...
    just wondering also do you still beta test your software???
    every minor update new bug's get introduced... and not checked by your staff!!!
    we pay for this....
    looks like you changed the business plan to make more money... MONEY IS OUR GOD @ UNITY3D
    loyal customers are our beta testers... but don't tell them ;-)
    we had much better times with Unity as of now....
    no communication... forums are waste of time... no support to contact for help...
    but shareholders value is important... the rest will do ehh ... that's how it is now...
    i'm User of day 1... when Unity was Mac OS X only ... was much better times as now...
    M.
     
    freakrho, Jeloz and Conferno like this.
  43. eltomek0

    eltomek0

    Joined:
    Sep 2, 2019
    Posts:
    2
    I can't make a Linux "code" (Visual Studio Code) editor properly displaying IntelliSense information.

    Say, I type "Input." and press Ctrl+Space, I'd expect to see the routines like GetKeyDown, but instead I just see a list of "Generic", "Input", "Log", etc. and not subroutines of Input class.
    Screenshot_20190908_005418.png

    I installed extensions like Debugger for Unity and C# for Visual Studio Code (powered by OmniSharp).
    .sln and .csproj files are present.

    mono installed and working:
    $ mono --version
    Mono JIT compiler version 5.18.0.240 (Debian 5.18.0.240+dfsg-2ubuntu2 Wed Apr 17 23:39:09 UTC 2019)
    Copyright (C) 2002-2014 Novell, Inc, Xamarin Inc and Contributors. www.mono-project.com
    TLS: __thread
    SIGSEGV: altstack
    Notifications: epoll
    Architecture: amd64
    Disabled: none
    Misc: softdebug
    Interpreter: yes
    LLVM: supported, not enabled.
    Suspend: preemptive
    GC: sgen (concurrent by default)


    EDIT: fixed it by updating mono to 6.0 (see https://github.com/OmniSharp/omnisharp-vscode/issues/3076 updating mono to 5.20 is claimed to fix it too).
     
    Last edited: Sep 8, 2019
    Eyap likes this.
  44. Conferno

    Conferno

    Joined:
    Feb 27, 2014
    Posts:
    32
    It seems it worked! Thanks man!
    Also, accept your words about Unity testing team. Also, the main competitor has gone quite far in quality and the level of development of the engine, while unity are barely developing similar functions. And also the majority of the community do more complex and cool things than the unity team itself. I hope the unity gets better...
     
    Muckel likes this.
  45. adityapatnaik25

    adityapatnaik25

    Joined:
    Sep 19, 2019
    Posts:
    1
    Install .net framework 4.7.1 developer pack


    Hope it helps!
     
    rendergo likes this.
  46. samf1111

    samf1111

    Joined:
    Sep 18, 2019
    Posts:
    2
    I FINALLY GOT IT!

    install your preferred version of unity, then, on the modules page, select VS Code. YAY YAY YAYAYAYAYAY!!
    i'm just as happy as you are!

    note: you may need to uninstall your unity before doing this.

    please press like in bottom left to grab other troubled users to this solution
     
    Last edited: Sep 22, 2019
  47. ktpttd

    ktpttd

    Joined:
    Aug 2, 2017
    Posts:
    3
    Sorry, I can not find VSCode module in Module page(Unity hub). Could you please post screenshot? Thank you so much!.
     
    nnagle likes this.
  48. AnomMahartha

    AnomMahartha

    Joined:
    Jul 25, 2018
    Posts:
    2
  49. ktpttd

    ktpttd

    Joined:
    Aug 2, 2017
    Posts:
    3
  50. hunabku94

    hunabku94

    Joined:
    Jun 12, 2017
    Posts:
    35
    VSCode and 2019.2 Unity actually need dotnet preview (3.0) and msbuild 16.3 to works