Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question Unity Extension for Visual Studio Code - Compilation errors suppressed until you open file

Discussion in 'Code Editors & IDEs' started by lcompton, Aug 15, 2023.

  1. lcompton

    lcompton

    Joined:
    Mar 31, 2018
    Posts:
    102
    I recently installed the Unity Extension for Visual Studio Code and configured my Unity project to use VSCode. It's working seamlessly, except for one problem. If there are compilation errors in C# scripts, the errors are displayed in the Unity console, but are hidden in VSCode until you open the file containing the errors. With the old Unity package, every C# file containing errors would have their name highlighted in red automatically. With the new configuration, the filenames are displayed in white (or whatever the there-are-no-problems color is) until the file is opened, when the errors are detected and displayed in the editor and directory hierarchy.

    Is there any way to configure Unity Extension for Visual Studio Code to indicate errors before opening the files?
     
    Last edited: Aug 16, 2023
  2. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    5,078
    What Unity version and which VS Code package?

    Unity VS Code support has been deprecated, but then very recently a new package was announced or released as experimental/preview I think. So it matters which of these you are using.

    Generally speaking I always recommend to stay clear of VSCode for Unity work, especially if you are a) a beginner because you get to have issues you needn‘t have for which you get little to no help and b) professionals as you will waste time (aka money) fighting issues few other people have and lack of tool support slowing down development, greatly offsetting the few seconds saved on launching VSCode compared to VS.

    VSCode has some merits on OSX and is certainly useful on Linux.
     
  3. lcompton

    lcompton

    Joined:
    Mar 31, 2018
    Posts:
    102
  4. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    5,078
    Yeah I share my opinion here and there mainly in an effort to keep the number of foolish VSCode users to a minimum. At least until it‘s actually mature and MS has shown they really mean it this time (perhaps more so than their VS support for Unity). ;)
     
  5. sailro

    sailro

    Microsoft

    Joined:
    Jul 30, 2014
    Posts:
    167
    Make sure you enabled (analyzer + compiler) background analysis for the whole solution (only open files by default) in VSCode settings:

    upload_2023-8-15_21-36-57.png

    And you can even "force" a problem-refresh by triggering a dotnet build.
     
    lcompton likes this.
  6. lcompton

    lcompton

    Joined:
    Mar 31, 2018
    Posts:
    102
    That sure looks like it should fix the problem, but sadly it doesn't. I changed those settings for both User and Workspace. The errors still don't get detected until you open the files.

    What additional information should I provide to assist with figuring this out?
     
  7. sailro

    sailro

    Microsoft

    Joined:
    Jul 30, 2014
    Posts:
    167
    Please use Help/Report issue in VSCode so we can track this.

    Any error message if you try to build from VSCode ? Perhaps you can find an error message in one of the output sources:
    upload_2023-8-16_9-11-30.png

    I tried on my side with several projects (small to mid size, and it was working as expected).
     
  8. lcompton

    lcompton

    Joined:
    Mar 31, 2018
    Posts:
    102
    I created an issue...
    Building yields very inconsistent results. After waiting for minutes, it finds lots of errors, none of which are cited in Unity. The following were found when my project contained no errors...
    Problems.jpg
     
    sailro likes this.
  9. lcompton

    lcompton

    Joined:
    Mar 31, 2018
    Posts:
    102
    I redownloaded my project from SCM to start from a clean slate. VS Code is finding compilation problems, although inconsistently. Here are some variants I've seen...
    • A few legit warnings are found along with 20 or so others that are not cited by Unity. This happens more often than not.
    • Hundreds of errors are cited having to do with items in my various script subdirectories not being found. None of the errors are cited by Unity.
    • Hundreds of errors are cited having to do with System.Void, System.int32, etc. not being found. None of the errors are cited by Unity.
    What it never finds is my little syntax error, unless I open the file that it's in.
     
  10. Malforacic105

    Malforacic105

    Joined:
    Aug 17, 2022
    Posts:
    4
    I had both of these problems and I fixed them by setting both of the Background Analysis options in VS Code to fullSolution, updating the visual studio editor package in Unity, updating to .NET 8.0, deleting all of the files alongside the .csproj files in my projects root directory, and then regenerating project files with only the first two boxes checked under 'Generate .csproj files for:'.

    This has worked so far, though it takes a while for the error console to update for whatever reason.