Search Unity

Can't get VSCode to work properly with Unity

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

  1. Himik_90

    Himik_90

    Joined:
    Jan 19, 2017
    Posts:
    1
    Hello everyone,
    I had the same issue with VS Code intellisense not showing up (for Unity API).
    I'm using Linux Lite 4.6(Ubuntu 18.04 LTS), AMD Athlon II X2, Unity (2019.2.8f1).
    My first steps were:
    - Install .Net SDK (v3.0) following instructions from official site (https://dotnet.microsoft.com/download);
    - Install VS Code. (Install C# extension);
    - Set Visual Studio Code as external editor (in Unity);
    and... nothing had happen. :(
    Then I decided to use MonoDevelop IDE and use it for editing Unity scripts (https://www.monodevelop.com/download/#fndtn-download-lin-ubuntu).
    I set external editor as Mono (not showing up in select box. You have to provide path to executable)...
    and it worked perfectly!
    But using MonoDevelop strangely increased my CPU usage to high values and i decided just for experiment use VS Code again! And it worked! Suddenly Intellisense started to work!
    That was solution in my case. Hope that this solution will work for you. ;)
     
    Last edited: Oct 11, 2019
  2. Tinus

    Tinus

    Joined:
    Apr 6, 2009
    Posts:
    437
    Spent all day fixing an issue very similar to this, on Windows 10.

    Since using various 2019.2.x editor versions I would occasionally get Unity into a state where it would not be able to launch VSCode at all.

    VSCode child processes would show nested underneath the Unity Editor process in the Task Manager, but no code window would actually show. I definitely thought it strange that Code would be launched as a sub-process, but didn't know what to make of it for a good while.

    On closing Unity, the sub processes would be orphaned, and needed to be ended manually before VSCode could be launched as standalone again.

    No problems mentioned in either Unity or VSCode log files.

    Stuff I tried that didn't work:
    • Install Visual Studio 2019 latest version to to get MSBuild 16.3.x
    • Install DotNet core 3.0.x
    • Install latest Mono SDK
    • Install DotNet 4.7.1 SDK (was already installed)
    • Changing the way Unity passes command line arguments
    • Disabling all VSCode extensions (safe mode)
    • Deleting all VSCode settings and reinstall from fresh download
      • This worked once, a month ago, but problem returned today
      • Got it to launch properly once, but it broke soon after
    • Install VSCode Insiders Edition
    • Install Unity 2019.3.x beta
    Installing the 2019.3.x beta did point out something useful! In the preferences panel, the UI for selecting External Script Editor now points you to two options for a VSCode install:

    upload_2019-10-11_18-41-52.png

    And it lists the option for /bin/code.cmd, which I only then remembered is what I used 6 months ago. Somewhere down the line I had configured it to use the Code.exe and never looked back. *facepalm*

    After setting my editors to use /bin/code.cmd, launching VSCode from Unity appears to work again, including in earlier 2019.2.x versions of the editor.

    Not a batch file expert, but code.cmd apparently sets just enough context to make it work:

    Code (CSharp):
    1. @echo off
    2. setlocal
    3. set VSCODE_DEV=
    4. set ELECTRON_RUN_AS_NODE=1
    5. "%~dp0..\Code.exe" "%~dp0..\resources\app\out\cli.js" %*
    6. endlocal
    (edit: only just noticed that this thread is in the Linux section of the forums... oh well)
     
    Last edited: Oct 11, 2019
  3. hunabku94

    hunabku94

    Joined:
    Jun 12, 2017
    Posts:
    50
  4. Lasiloper

    Lasiloper

    Joined:
    Aug 8, 2017
    Posts:
    10
    I tried several solutions but none worked for me. But finally I fixed my vscode integration.
    1. Reset packages and update vscode package to 1.1.2. Not really work. This may not be help because Unity still open project in Visual Studio 2019 community instead of vscode.
    2. Use this script, from https://www.reddit.com/r/Unity3D/comments/32bk48/how_to_remove_an_item_from_the_external_script/ to reset unity user preference.
    Code (CSharp):
    1. using UnityEditor;
    2. using UnityEngine;
    3.  
    4. public class EditorResetPrefs : MonoBehaviour {
    5.     [MenuItem ("Edit/Reset Preferences")]
    6.     static void ResetPrefs() {
    7.         if(EditorUtility.DisplayDialog("Reset editor preferences?", "Reset all editor preferences? This cannot be undone.", "Yes", "No")) {
    8.             EditorPrefs.DeleteAll();
    9.         }
    10.     }
    11. }
    3. Select vscode as external script editor and everything worked again.
     
  5. Hallur90

    Hallur90

    Joined:
    Dec 4, 2017
    Posts:
    55
    I have a project where I suddenly wasn't able to open VScode via Unity.

    However if I create a new project it works as expected.

    Seems like something with the project got corrupted... any ideas?
     
  6. Hallur90

    Hallur90

    Joined:
    Dec 4, 2017
    Posts:
    55
    Reinstalling vscode worked for me.
     
  7. Lasiloper

    Lasiloper

    Joined:
    Aug 8, 2017
    Posts:
    10
    I reset unity user preference then I can open vscode via Unity but now it won't compile when I change code. I don't want to reinstall vscode so I use VS 2019 community now.
     
  8. GDevYoussef

    GDevYoussef

    Joined:
    Nov 3, 2019
    Posts:
    1
    I deleted the Assembly, sln and userprefs files from the game folder then open it again from unity hub after that VSCode works well
     
  9. bdilloughery_mvla

    bdilloughery_mvla

    Joined:
    Sep 22, 2017
    Posts:
    39
    Any other fixes?

    My problem:
    Unity 2019.2.7f, can't open VS code with Intellisense/Omnisharp working. Double clicking on files in Unity does nothing except start rogue VS code processes in task manager that I can end task on. Manually opening VS code is great but would love auto-complete to work.

    I tried:
    1. Uninstalling and reinstalling VS code
    2. Reinstalling .NET targetting framework 4.7.2 dev pack
    3. Resetting the external tools preferences to the VS Code exe
    4. Deleting project's Assembly-Csharp.csproj and *.sln from project folder and reopening from Unity Hub

    So far no go.
    I have a bunch of new computers and this error seems to randomly re-crop up on just a few machines. Most are working just fine, but a few just loose the ability to open files. About 2/15 at any given time. Usually one of the 4 methods above fixes the issue. This time it is being especially stubborn.

    Other ideas? Posting to main forum too ...
     
  10. cobalt_strike

    cobalt_strike

    Joined:
    Feb 24, 2019
    Posts:
    1
    So, best way to go about this. For Ubuntu 18.0.4 LTS

    1) First download and install MonoDevelop -> https://www.mono-project.com/download/stable/ location /usr/bin/mono


    2) Then get the .net 3.0 framework via terminal

    wget -q https://packages.microsoft.com/config/ubuntu/18.04/packages-microsoft-prod.deb -O packages-microsoft-prod.deb
    sudo dpkg -i packages-microsoft-prod.deb
    sudo add-apt-repository universe
    sudo apt-get update
    sudo apt-get install dotnet-sdk-3.0


    3) Download Visual Studio. Location is /usr/bin/code

    4) Open Visual Studio and Download c# for Visual Studio and Debugger for Unity extensions via the extensions panel on left hand side.

    5) Click debugger on left panel select from the drop down menu "Unity Debugger" near green play button. Then click the settings right next to it and it should open the launch.json file

    5) Close Visual Studio and open Unity Project, then go to edit -> preferences -> external script editor -> select /usr/bin/code

    6) MAKE NEW SCRIPT in your project and double click to open. It should pop up with some errors on the bottom right. Fix them by following the suggestions(The error that says "Unable to watch for file changes in this large workspace.") Is okay to ignore.

    7) Close Unity and Visual Studio. Re-open Unity and then click on that new script that you just made. It should work from now on. At least it did for me!!!
     
  11. bdilloughery_mvla

    bdilloughery_mvla

    Joined:
    Sep 22, 2017
    Posts:
    39
    Thank you!

    The fix I finally found for Windows 10 is:

    In Unity --> Top Menu --> Edit --> Preferences --> External Tools --> External Script Editor --> Select "Browse"

    In the past, I had navigated to: "C:\Program Files\Microsoft VS Code\Code.exe"

    Instead, navigate to: "C:\Program Files\Microsoft VS Code\bin\"
    Then change the option of viewing only *.exe files to viewing all files
    Select "code.cmd"
    ... so overall the path on mine is "C:\Program Files\Microsoft VS Code\bin\code.cmd"


    This fix came from:
    https://issuetracker.unity3d.com/is...external-script-editor-is-set-to-code-dot-exe

    Specific solution came from:
    @Anthony0506 By changing the "External Script Editor" in the editor preferences, manually browsing to ".../Microsoft VS Code/bin/code.cmd". The set editor still appears as "Visual Studio Code" though.
     
  12. lordkiz

    lordkiz

    Joined:
    Dec 29, 2019
    Posts:
    1
    This is one solution Mac Users must apply.
     
  13. allybey34

    allybey34

    Joined:
    Apr 21, 2019
    Posts:
    5
  14. MadWatch

    MadWatch

    Joined:
    May 26, 2016
    Posts:
    112
    You might want to try the solution I posted here.
     
    Achie1 likes this.
  15. Deleted User

    Deleted User

    Guest

    Doesn't work for me.
     
  16. mechane

    mechane

    Joined:
    Nov 17, 2018
    Posts:
    6
    Thank you very much ! I had no .sln file in my directory so I tried your solution. That was it , it works now !
     
  17. Achie1

    Achie1

    Joined:
    Jan 14, 2018
    Posts:
    26
    This is a little tips I want to share. When I open a new project, Intellisense doesn't work automatically. But 2 or 5 seconds later, There is a pop up message stating that : "Some projects have trouble loading. Please review the output..."
    I click on "Show Output". Visual studio code opens my project and restores Intellisense by opening a file with the extension "sln". It also downloads the required files if not.
    But don't forget to install the required Package (C# for Visual Studio, Debugger for Unity)
     
  18. Potato_Lord913

    Potato_Lord913

    Joined:
    Dec 3, 2017
    Posts:
    2
    Arch user here

    I did many things until I got proper intellisense and I think maybe one or two of the things that I did was unnecessary but here it goes

    1. replaced my code package with the official binary version visual-studio-code-bin AUR
    2. following this wiki page I made sure mono is intalled (I even installed mono-tools)
    3. following this wiki page I made sure omnisharp-roslyn-http-bin AUR is intalled.
    4. made sure the file /usr/bin/code indeed exists and unity is using it as an external IDE
    5. made sure the Generate all .csproj files tick box is checked (which is found in the same external tools unity window)
    6. from unity Assets > Open C# Project
    7. vscode will now prompts me to install the C# extension
    8. after that it started downloading and installing some C# debugger in the internal terminal
    9. ???
    10. profit

    Now you will have to give your vscode a second or two each time after launch so it loads all the unity stuff and get proper intellisense going (just like how it is in Visual Studio on windows)

    I'm guessing even if you're not running arch, What I just said might all or partially apply to any or most linux distros, In general you just have to find the right packages for yourself.

    I hope my research will be of help to a poor soul in the future. Cheers.

    upload_2020-3-2_7-4-43.png

    upload_2020-3-2_7-5-55.png
     
  19. hunabku94

    hunabku94

    Joined:
    Jun 12, 2017
    Posts:
    50
    Hey, i'm ArchLinux user too.

    I only need to visual-studio-code-bin AUR, mono and dotnet-sdk for works.

    In Unity, select usr > bin > code with menu in Preferences / External tools.
    Also in Package Manager, rollback Visual Studio Code Editor from 1.1.4 to 1.1.3 (buggued, 3 month fixed but no 1.1.5 release this day)

    In code, installed unity3d-pack only
     
  20. Deleted User

    Deleted User

    Guest

    Does VS Code write Start(), Update() and the other Monobehaviours automatically for you?

    Try this: write
    Code (CSharp):
    1. void sta
    in a new script and push Tab or Enter. If it works correctly, VS Code should automatically write the full function:
    Code (CSharp):
    1. private void Start()
    2. {
    3.  
    4. }
    Write:
    Code (CSharp):
    1. void ontrig
    and VS Code should display a whole list of possibilities to choose from.

    Is this supposed to work? Will it work one day if it doesn't yet?

    :)
     
    Last edited by a moderator: Mar 12, 2020
  21. Hypo386

    Hypo386

    Joined:
    Feb 16, 2018
    Posts:
    1
    Ubuntu 18.04

    I was upgrading Unity to latest version and had trouble with Omnisharp's plugin for vscode. After downgrading hinting wasn't there.

    Solution for me was to got to Assets -> Open C# project

    Then restart vscode.
     
  22. bdilloughery_mvla

    bdilloughery_mvla

    Joined:
    Sep 22, 2017
    Posts:
    39
    The solution that works 99% of the time for me is:

    Go to Unity --> Edit --> Preferences --> External Tools
    Select Browse
    Go to C:/Program Files/Microsoft VS Code/bin
    in the bottom right, select to view "All Files" and not "exe files"
    You will see two options. Select the "Windows Command..." one that is a *.cmd file.

    Cheers,
    Brendan
     
    demanzonderjas likes this.
  23. Deleted User

    Deleted User

    Guest

    That's for Windows not for Linux. :)
     
  24. unit_dev123

    unit_dev123

    Joined:
    Feb 10, 2020
    Posts:
    989
    A lot of features, like directx are not support on linux build. That is why many develop on windows.
     
  25. Deleted User

    Deleted User

    Guest

    Irrelevant. This thread is about the Linux editor, not developing under Windows.
     
  26. unit_dev123

    unit_dev123

    Joined:
    Feb 10, 2020
    Posts:
    989
    Sir you are initially correct, with topic at hand, but many consider linux dev problematic, as lots of feature on linux are unstable and has small user base. You can see steam stats for more references on operating system support, if you are making games just for yourself, linux will be fine, as long as you not do anything fancy.
     
  27. Deleted User

    Deleted User

    Guest

    Irrelevant. Out of topic. The question is about the Linux version of the editor. Look at the top of this page.
     
  28. miniwolf_unity

    miniwolf_unity

    Unity Technologies

    Joined:
    Apr 10, 2018
    Posts:
    138
    This problem would be solved by implementing specific unity related functionality in OmniSharp. I do not see this happening unless someone went and made a custom fork of the omnisharp to support these extra magic functions.
    The way that these methods work is that we allow them to be written, and if they exist we call them through reflection. Therefore intellisense does not work out of the box.
     
  29. Deleted User

    Deleted User

    Guest

    Well, at least, thank you for your answer! Now I know what to think. I hope someone, some day will come up with the custom fork you mention; in the meantime, I'll do without it.

    Thank you again! :)
     
  30. Novack

    Novack

    Joined:
    Oct 28, 2009
    Posts:
    844
    Just curious, the VSCode extensions for Unity that cover that, wont work on linux?
     
  31. miniwolf_unity

    miniwolf_unity

    Unity Technologies

    Joined:
    Apr 10, 2018
    Posts:
    138
    It should work for linux. The vscode extension should work across all three platforms, linux, osx and windows.
     
    Novack likes this.
  32. Deleted User

    Deleted User

    Guest

    I don't understand, you said in your post #78 that it was not possible in Linux unless someone wrote a special fork for OmniSharp?

    That's most probably what @Novack was asking about.
     
  33. Lightning_A

    Lightning_A

    Joined:
    Nov 30, 2018
    Posts:
    7
    For me the problem was there were two .sln files and that was confusing vscode

    (I deleted the old .sln)
     
  34. BeardMen4Lyfe

    BeardMen4Lyfe

    Joined:
    Jan 23, 2020
    Posts:
    1
    I followed the tutorial from Microsoft for VS Code with Unity and it seemed to finally do the trick... https://code.visualstudio.com/docs/other/unity

    Steps I took:

    1. Installed https://dotnet.microsoft.com/download
    2. Installed https://www.mono-project.com/download/stable/
    3. Installed C# extension in VS Code.
    4. Unity > Preferences (cmd + , on Mac) > External Tools (left toolbar) > External Script Editor > Visual Studio Code.
    5. **Then this is the trick I found to work after doing all of this...** I open up VS Code prior to starting my Unity Project and manually go into the Unity Project folder and open up everything in VS Code FIRST. Then, with that project already open and working in VS Code with Intellisense, I double click the script in Unity and it will open it up in the already opened VS Code editor and have Intellisense already working! Do my normal workflow for the day and close everything down... then when I start up the next time, just be sure to open the project in VS Code FIRST and then VS Code will recognize it's a C# project and initiate Intellisense and all that jazz.

    Hope this helps!
     
  35. sachindas

    sachindas

    Joined:
    Oct 19, 2015
    Posts:
    2
    Worked For me
     
  36. Acazied

    Acazied

    Joined:
    Mar 2, 2016
    Posts:
    47
  37. oniMaker

    oniMaker

    Joined:
    Jul 4, 2015
    Posts:
    1
    I ran into the same issue as APSchmidt (on OSX though, not Linux) and this was the first explanation I found as to what was going on. Thanks for clearing that up!

    Out of curiosity, how do these "magic" functions appear in intellisense for Visual Studio (not VSCode)?
     
  38. miniwolf_unity

    miniwolf_unity

    Unity Technologies

    Joined:
    Apr 10, 2018
    Posts:
    138
  39. Deleted User

    Deleted User

    Guest

  40. Deleter

    Deleter

    Joined:
    Dec 21, 2012
    Posts:
    23
    -I couldn't get things work with VS Code then I
    -found the VS Code extension in asset store
    -installed it, then I went to Unity PReferences,
    -VS Code (bottom)
    -I checked everything useful in this Preference stuff
    -then clicked on my sln project on the blue stuff at bottom of the vs code editor
    => it worked
     
  41. wintergpt45

    wintergpt45

    Joined:
    Apr 27, 2020
    Posts:
    1
    Omg thank you so much ! Was stuck on this issue for hours.
     
  42. k_a_p_i_l

    k_a_p_i_l

    Joined:
    Dec 25, 2019
    Posts:
    1
    Thank you so much. i have been working on it for a long time and not getting any success. You gave this easy solution, which worked for me.
    Thank you so much.
     
  43. borsnoemi11

    borsnoemi11

    Joined:
    Sep 1, 2019
    Posts:
    1
    Hello guys!

    I had the same problem with Unity 2019.3.9f1, here's what solved it for me finally.

    I did a lot of things mentioned above, downloaded the SDK, manually selected the Code.exe in the
    Edit > Preferences > External Tools, but that alone did not seem to work.

    Then I checked this magic setting:
    upload_2020-5-7_22-15-34.png
    Closed VS Code, then opened a script file from Unity. The VS Code opened, and voilá! Intellisense and error detection!
     
    zessirb and vmnetcetera like this.
  44. THEplayer321

    THEplayer321

    Joined:
    Nov 3, 2019
    Posts:
    2
    i clicked all the options below the external script editor, clicked regenerate project files and it worked
     
  45. Achie1

    Achie1

    Joined:
    Jan 14, 2018
    Posts:
    26
    With the latest update, everything is fine now. I have intellisense and there is no bug anymore. I use Ubuntu 20.04.
     
  46. RpxdYTX

    RpxdYTX

    Joined:
    May 28, 2020
    Posts:
    7
    On my VScode the preferences aren't in edit, they are on file and when i touch it nothing like Unity preferences or external tools appear so how can i do this
     
  47. miniwolf_unity

    miniwolf_unity

    Unity Technologies

    Joined:
    Apr 10, 2018
    Posts:
    138
    All these settings are located in the Unity Editor, not in VSCode.
     
  48. RpxdYTX

    RpxdYTX

    Joined:
    May 28, 2020
    Posts:
    7
    Oh... thanks (i'm a begineer in unity) ;-;
     
  49. miniwolf_unity

    miniwolf_unity

    Unity Technologies

    Joined:
    Apr 10, 2018
    Posts:
    138
    No worries, feel free to ask any questions you may have here on the forums.
     
  50. ctacb

    ctacb

    Joined:
    Jul 6, 2020
    Posts:
    1