Search Unity

Visual Studio Code not working with Unity?

Discussion in 'Getting Started' started by Green11001, Jun 23, 2019.

  1. Green11001

    Green11001

    Joined:
    Apr 14, 2018
    Posts:
    397
    I have been using Visual Studio Code for a while and I have had no issues. However, suddenly, it is as if Vs code does no understand unity script at all. There is little auto correct, and when there is it corrects something that is right to something I don't want. It does not properly show errors either, even if they show in the unity log. How do I fix this? It seemed to start when I have created a new project.
     
  2. Green11001

    Green11001

    Joined:
    Apr 14, 2018
    Posts:
    397
    Anyone?
     
  3. Homicide

    Homicide

    Joined:
    Oct 11, 2012
    Posts:
    657
    Did you install new version of VS?

    Make sure its entry is set in preferences/external editor.

    GL
     
  4. Green11001

    Green11001

    Joined:
    Apr 14, 2018
    Posts:
    397
    I reinstalled and checked entry. I have discovered that apparently Vs code works for one project but not for another project?
     
  5. arahmitz

    arahmitz

    Joined:
    Jun 25, 2019
    Posts:
    25
    Do you have snippets installed?
     
  6. Green11001

    Green11001

    Joined:
    Apr 14, 2018
    Posts:
    397
    Never heard of that, so I'm pretty sure not unless it installs along visual studio
     
  7. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    Delete the local .sln and other VS files from the root of the project and try again (make a backup first of course)
     
    EvilMog99, UpsideUp91 and Ryiah like this.
  8. Green11001

    Green11001

    Joined:
    Apr 14, 2018
    Posts:
    397
    Ummm..... where would those be?
     
  9. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    As mentioned, at the root of the project. Along with /Assets, /ProjectSettings etc. At that same level. At least that is where Visual Studio places them, not sure about Visual Code.
     
  10. Green11001

    Green11001

    Joined:
    Apr 14, 2018
    Posts:
    397
    I deleted everything I could see relating to vs code and it appeared they were rebuilt when I started Unity. The issue was not fixed....
     
  11. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    No, they are not "rebuilt", only when you launch Visual Code or Visual Studio.
     
  12. Green11001

    Green11001

    Joined:
    Apr 14, 2018
    Posts:
    397
    Yea they were "rebuilt" when i launched vs code I mean cuz there was a lag spike or something. Sorry
     
  13. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    Yes, that is expected. Sorry it's still not working for you. What's different between your two projects, are they located in the same area on your disk, like under C:\Users\[name]\Documents\ ? (to confirm permissions) . What about a brand new project?
     
  14. Green11001

    Green11001

    Joined:
    Apr 14, 2018
    Posts:
    397
    If it helps, I have had this problem for a long time with monodevelop on all my problems, and because of that I thought it was monodevelop being broken, so I switched to Vs Code. It seemed to work until I have created a new project and it did not work.
    Made a new project, does not work either.
    Old project should not have anything different about it, as I would not tamper with the files for no reason. However, there was a sizable time difference between the creation of the old project and the new project.
     
  15. Green11001

    Green11001

    Joined:
    Apr 14, 2018
    Posts:
    397
  16. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    Try using Visual Studio 2017 instead of Visual Code
     
  17. Green11001

    Green11001

    Joined:
    Apr 14, 2018
    Posts:
    397
    Tried using visual studio and it seemed to work
     
    Joe-Censored likes this.
  18. rustum

    rustum

    Unity Technologies

    Joined:
    Feb 14, 2015
    Posts:
    190
    Have you tried installing the Visual Studio Code Editor package from the package manager?

    Visual Studio Code Editor package.png
     
    JeffDUnity3D likes this.
  19. Green11001

    Green11001

    Joined:
    Apr 14, 2018
    Posts:
    397
  20. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    I believe it was a suggestion. But it sounds like you already have Visual Studio working.
     
  21. Green11001

    Green11001

    Joined:
    Apr 14, 2018
    Posts:
    397
    Hmmm...... it seems updating unity seemed to fix the issues.
     
  22. uncleciba2game

    uncleciba2game

    Joined:
    Jul 22, 2016
    Posts:
    11
    I can't debug unity with visual studio ,I already install "VS tool for unity".
    why I cannot find "Visual Studio Editor" or "Visual Studio Code Editor" in package manager (both 2018.0.2f2 and 2019.1.9f1)
    how can I install them?
    And I cannot see "VS tool for unity enabled " on "Help/About" windows in 2018.0.2f2
    Is there 2 part for "VS tool for unity", one installed in VS,another in UnityEditor?
     
  23. Green11001

    Green11001

    Joined:
    Apr 14, 2018
    Posts:
    397
    I could not find them either (in my older version, idk about new one) in package manager, which is what prompted me to update unity
     
  24. arahmitz

    arahmitz

    Joined:
    Jun 25, 2019
    Posts:
    25
    I wonder - where you can download it?
     
  25. snewson

    snewson

    Joined:
    Apr 23, 2020
    Posts:
    1
    In Unity, go to Edit > Preferences, and make sure that Visual Studio is selected as your preferred external editor. This solution worked for me.

    you can find more information in the Unity User Manual (2019.3) > Working in Unity > Editor Features > Visual Studio C# integration
     
    uyanneo likes this.
  26. Paxtonnguyen

    Paxtonnguyen

    Joined:
    Nov 16, 2020
    Posts:
    1
    well my unity will not connect with visual studio I don't know if it is because I don`t have a account for it or something else
     
  27. carterclough99

    carterclough99

    Joined:
    Jan 6, 2021
    Posts:
    2
    I have the same problem.
     
    Miscellaneous likes this.
  28. Miscellaneous

    Miscellaneous

    Joined:
    Sep 24, 2013
    Posts:
    53
    Visual Studio CODE used to work, but not anymore, problem 8+ months...
     
  29. Burnsnotice

    Burnsnotice

    Joined:
    Jul 9, 2017
    Posts:
    3
    I could be wrong, but after spending most of my Friday refraining from smashing technology due to frustration with this very issue I noticed that I wasn't signed in to VS2019. Took a deep breath created the damn account in ten seconds and voila, no more errors. GD Microsoft throwing masochistic shade...
     
  30. SebastianCory

    SebastianCory

    Joined:
    Apr 20, 2020
    Posts:
    1
    these forums help out so much!
     
  31. uyanneo

    uyanneo

    Joined:
    Mar 20, 2021
    Posts:
    3
    Coming backwards in time: Thanks!
     
  32. zacharyyates

    zacharyyates

    Joined:
    Jan 5, 2020
    Posts:
    4
    For folks having this problem with vs-code, here's a few troubleshooting steps:

    1. Make sure you have the Visual Studio Code Editor package added to your project (as the Unity folks mentioned)

    2. Visual Studio Code relies on the C# extension (https://marketplace.visualstudio.com/items?itemName=ms-dotnettools.csharp) to provide intellisense, formatting, etc. Make sure you have this installed.

    3. The C# extension relies on the OmniSharp server (https://www.omnisharp.net/) to work, which is installed with the C# extension (no additional installation/download required). However, OmniSharp has it's own requirements, such as specific .Net versions. If your intellisense suddenly stops working in vs-code, this could be the issue. Open the terminal (CTRL+~), select the "Output" tab, and choose the "OmniSharp Log" from the drop down. You may see an error message like:

    [ERROR] Error: Found dotnet version 3.1.201. Minimum required version is 6.0.100.


    In this case you need to update the .Net SDK/Runtime on your machine.

    4. If you're on MacOS, you'll need to install a recent version of Mono: https://www.mono-project.com/download/stable/

    If you have a recent version installed and it's still not working, you may need to add it to your path. The best way to do this (IMO) is to create a symlink to your /usr/local/bin/ directory, explained here: https://stackoverflow.com/a/56291338/8360. This is the error you'll see in the Omnisharp Log:

    [ERROR] Error: Command failed: dotnet --version
    /bin/sh: dotnet: command not found


    5. Sometimes Omnisharp just needs to be restarted. In vs-code, CTRL+Shift+P opens the command pallete, then select "Omnisharp: Restart Omnisharp"

    6. Sometimes Omnisharp doesn't load the .sln file correctly. In this case, near the bottom of the vs-code window, in the status bar, there should be button to the right of a fire icon that allows you to select your Unity .sln file.

    Hope that helps.
     
    Last edited: Aug 16, 2022
  33. Ryanei_dy_Myrhona

    Ryanei_dy_Myrhona

    Joined:
    Mar 24, 2020
    Posts:
    4
    Hi, I'm also having this issue.

    I followed these instructions: https://code.visualstudio.com/docs/other/unity
    it failed.

    I downloaded this: https://dotnet.microsoft.com/en-us/download/dotnet/thank-you/sdk-7.0.101-windows-x64-installer
    I put that in a folder in my project root: https://www.nuget.org/packages/Microsoft.Unity.Analyzers/
    I wrote this .json file for omnisharp??
    I enabled this Roslyn whatever,
    I tried restarting OmniSharp, I tried findind error messages in the output window (it is EMPTY),
    I tried restarting the program after I removed the .sln file from my project,
    I installed the Package in the Packet Manager,
    I disabled and enabled back on each and every Extension,
    I looked for other Extensions that might do the trick,
    I scrolled through C# settings, scrolled throuch Unity settings in VSCode,
    I tried this: https://stackoverflow.com/questions...is-not-highlighting-compile-errors-in-my-code
    I restarted, restarted, restarted, edited files, saved, restarted, went to Unity, restarted.

    It doesn't change anything.
    It always shows these colors, it always turns from white to them after a split second, there are no red lines, no error marks, no errors in the console, as if everything was fine. It's not. I write a senseless sentence in here and it is told "this is fine!" I am losing my mind. Is this a setting? This syntax highlighting goes through all file types I open, no matter if it's .cs, or .toml, or .json, or .hlsl. It always looks exactly like this as if VSCode can't read file endings anymore?
    People told me to use program X or Y, that doesn't change the fact that all is set up for this one and that it's not working. Is it a setting? Is it a bug? Is it a flying pig? Who knows!

    Also: I AM getting scripting info, like, I start typing "FixedU" and it adds the "FixedUpdate () {}" into my file, just perfectly.
    The project this is happening on is cloned from AzureDevops. But this happened to projectless .TOML files, just the same, or to other files I opened up. I can't 100% predict where it comes from and if it's always like this, but obviously it acts as if there are no Extensions installed.

    I cannot uninstall the editor, I am afraid of losing connection to my repositories!

    Please help me!

    Attachment: My annoying issue:
    upload_2022-12-19_21-25-36.png
    My Extensions:
    upload_2022-12-19_21-28-40.png
     
  34. saturnvfive

    saturnvfive

    Joined:
    Dec 24, 2022
    Posts:
    1
    visual studio code for me works fine but it does sometimes not work on certain projects it just will legitimately have so many errors it just goes unresponsive
     
  35. AssassinBear23

    AssassinBear23

    Joined:
    May 5, 2019
    Posts:
    2
    I believe you are missing this extension, and I would recommend getting the C# Dev kit
    upload_2024-2-21_17-30-37.png