27

Problem: IntelliSense is not working for Unity specific methods and functions (i.e., Update, FixedUpdate, Awake, etc.).

It does work, however, for non Unity specific methods (i.e., IEnumerator, void, public, float, int, etc.) and for Unity specific variables (i.e., Gameobject, transform, camera, etc.) and Unity specific namespaces (i.e., UnityEngine, UnityEditor, Unity, etc.).

I am using: Visual Studio Code 1.41, Unity 3d 2018.4.15f1 (I have the same problem when using 2019.2.x).

I have tried the following solutions to no results:

  1. Using different versions of .NET
  2. Deleted vscode file within the project.
  3. Uninstalled and reinstalled both Unity and Visual studio.
  4. Changed <TargetFrameworkVersion>v4.7.1</TargetFrameworkVersion> to <TargetFrameworkVersion>(Currently installed version)</TargetFrameworkVersion> but unity automatically defaults back to v4.7.1

Possible problems:

  1. The sln file the project creates reads

    Microsoft Visual Studio Solution File, Format Version 11.00
    # Visual Studio 2010
    Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Assembly-CSharp", "Assembly-CSharp.csproj", "{B2B58FB2-4462-6B0C-A872-40DD957E5FE0}"
    EndProject
    Global
        GlobalSection(SolutionConfigurationPlatforms) = preSolution
            Debug|Any CPU = Debug|Any CPU
            Release|Any CPU = Release|Any CPU
        EndGlobalSection
        GlobalSection(ProjectConfigurationPlatforms) = postSolution
            {B2B58FB2-4462-6B0C-A872-40DD957E5FE0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
            {B2B58FB2-4462-6B0C-A872-40DD957E5FE0}.Debug|Any CPU.Build.0 = Debug|Any CPU
            {B2B58FB2-4462-6B0C-A872-40DD957E5FE0}.Release|Any CPU.ActiveCfg = Release|Any CPU
            {B2B58FB2-4462-6B0C-A872-40DD957E5FE0}.Release|Any CPU.Build.0 = Release|Any CPU
        EndGlobalSection
        GlobalSection(SolutionProperties) = preSolution
            HideSolutionNode = FALSE
        EndGlobalSection
        GlobalSection(MonoDevelopProperties) = preSolution
            StartupItem = Assembly-CSharp.csproj
        EndGlobalSection
    EndGlobal
    

    For some reason, the sln file seems to be used for Visual Studio 2010. I do not know if this is intentional or if this is the problem.

  2. When attempting solution 4, as stated above, Unity (or VS Code for all I know) automatically changes .NET version from whatever I manually typed to 4.7.1. I have 4.7.1 already installed so this may not be the problem.

Extra information:

Here is the omnisharp log:

Starting OmniSharp server at 2020. 1. 20. 오후 9:08:43
    Target: c:\Users\stpau\New Unity Project\New Unity Project.sln

OmniSharp server started.
    Path: C:\Users\stpau\.vscode\extensions\ms-vscode.csharp-1.21.9\.omnisharp\1.34.9\OmniSharp.exe
    PID: 2232

[info]: OmniSharp.Stdio.Host
        Starting OmniSharp on Windows 6.2.9200.0 (x64)
[info]: OmniSharp.Services.DotNetCliService
        DotNetPath set to dotnet
[info]: OmniSharp.MSBuild.Discovery.MSBuildLocator
        Located 1 MSBuild instance(s)
            1: StandAlone 16.3 - "C:\Users\stpau\.vscode\extensions\ms-vscode.csharp-1.21.9\.omnisharp\1.34.9\.msbuild\Current\Bin"
[info]: OmniSharp.MSBuild.Discovery.MSBuildLocator
        MSBUILD_EXE_PATH environment variable set to 'C:\Users\stpau\.vscode\extensions\ms-vscode.csharp-1.21.9\.omnisharp\1.34.9\.msbuild\Current\Bin\MSBuild.exe'
[info]: OmniSharp.MSBuild.Discovery.MSBuildLocator
        Registered MSBuild instance: StandAlone 16.3 - "C:\Users\stpau\.vscode\extensions\ms-vscode.csharp-1.21.9\.omnisharp\1.34.9\.msbuild\Current\Bin"
            CscToolExe = csc.exe
            CscToolPath = C:\Users\stpau\.vscode\extensions\ms-vscode.csharp-1.21.9\.omnisharp\1.34.9\.msbuild\Current\Bin\Roslyn
            MSBuildExtensionsPath = C:\Users\stpau\.vscode\extensions\ms-vscode.csharp-1.21.9\.omnisharp\1.34.9\.msbuild
            MSBuildToolsPath = C:\Users\stpau\.vscode\extensions\ms-vscode.csharp-1.21.9\.omnisharp\1.34.9\.msbuild\Current\Bin
[info]: OmniSharp.Cake.CakeProjectSystem
        Detecting Cake files in 'c:\Users\stpau\New Unity Project'.
[info]: OmniSharp.Cake.CakeProjectSystem
        Could not find any Cake files
[info]: OmniSharp.MSBuild.ProjectSystem
        Detecting projects in 'c:\Users\stpau\New Unity Project\New Unity Project.sln'.
[info]: OmniSharp.MSBuild.ProjectManager
        Queue project update for 'c:\Users\stpau\New Unity Project\Assembly-CSharp.csproj'
[info]: OmniSharp.Script.ScriptProjectSystem
        Detecting CSX files in 'c:\Users\stpau\New Unity Project'.
[info]: OmniSharp.Script.ScriptProjectSystem
        Could not find any CSX files
[info]: OmniSharp.WorkspaceInitializer
        Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.CSharpFormattingWorkspaceOptionsProvider, Order: 0
[info]: OmniSharp.MSBuild.ProjectManager
        Loading project: c:\Users\stpau\New Unity Project\Assembly-CSharp.csproj
[info]: OmniSharp.WorkspaceInitializer
        Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.RenameWorkspaceOptionsProvider, Order: 100
[info]: OmniSharp.WorkspaceInitializer
        Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.EditorConfigWorkspaceOptionsProvider, Order: 200
[info]: OmniSharp.WorkspaceInitializer
        Configuration finished.
[info]: OmniSharp.Stdio.Host
        Omnisharp server running using Stdio at location 'c:\Users\stpau\New Unity Project' on host 8980.
[info]: OmniSharp.MSBuild.ProjectManager
        Successfully loaded project file 'c:\Users\stpau\New Unity Project\Assembly-CSharp.csproj'.
[info]: OmniSharp.MSBuild.ProjectManager
        Adding project 'c:\Users\stpau\New Unity Project\Assembly-CSharp.csproj'
[info]: OmniSharp.MSBuild.ProjectManager
        Update project: Assembly-CSharp

How can I solve this problem? I also asked this question on both reddit and the Unity forums with no success.

mkrieger1
  • 19,194
  • 5
  • 54
  • 65
Paul
  • 273
  • 1
  • 4
  • 6

19 Answers19

43

In the latest version of VS Code and Omnisharp, I had the same problem and solved enabling this option in Unity:

Edit > Preferences > External Tools > Generate all .csproj files.

Leonardo Tada
  • 539
  • 3
  • 3
  • 4
    Sadly, that might work once but you have to keep doing it. Intellisense keeps disabling even after you found a way to get it working for a short while. – Kokodoko Sep 11 '20 at 16:10
  • For me, when IntelliSense does not show after doing that on Unity, restarting Omnisharp solve. – luturol Apr 29 '21 at 13:29
  • I was stuck with this IntelliSense issue in VSCode, well the below answer helped me out as Omnisharp was not able to locate the .net build tools. https://stackoverflow.com/a/72386799 – Questioner Jul 11 '22 at 18:48
  • After installing dotnet and adding it to path, installing .net4.7.1 SDK and doing this solved it for me. Omnisharp needed to be restarted to generate everything and add them to csproj again. – Ozgur O. Dec 05 '22 at 05:15
27

Had the same problem using VSCode 1.41.1 and Unity 2019.4.0f1.

I was able to fix it by following these steps:

  1. download & install the .Net Framework 4.7.1 Developer Pack here:

https://dotnet.microsoft.com/download/dotnet-framework/thank-you/net471-developer-pack-offline-installer

  1. in Unity, go to Edit > Project Settings > Player > API Compatibility Level and change it to .NET 4.x

  2. restart VSCode & Unity

IntelliSense works fine now and I don't get any errors when loading .cs files in VSCode anymore.

friartuck
  • 468
  • 5
  • 6
9

MacOS (VSCode 1.56.2 + Unity 2020.3.10f1)

I was able to make Unity + VSCode intellisense happy by taking these steps:

  1. Installed Mono ($ brew install mono)
  2. Ensure that Omnisharp uses Mono:

2.1) VSCode > Code > Preferences > Settings...
2.2) Search "global mono"...
2.3) Set "Use Global Mono" to "always"...
2.4) Restart Omnisharp (blue button in popup message at bottom)

  1. In Unity, ensure .csproj files are created

3.1) Unity > Preferences > External Tools > change External Script Editor setting to "Visual Studio Code" 3.2) Unity > Preferences > External Tools > Generate all .csproj files (check all checkboxes)

With these steps, I am able to target .Net Standard 2.0 in my Unity project and use intellisense in VSCode.

Dharman
  • 30,962
  • 25
  • 85
  • 135
Rich G
  • 256
  • 2
  • 8
  • This worked for me! For ARM (M1) based mac I had to install via brew this way: https://stackoverflow.com/a/64997047. Also I had previously set a mono path in the C# VS Code plugin setting, I had to delete that entry to get this post's steps to work. Thanks!! – user2812481 Nov 28 '21 at 03:21
  • Thanks... This worked for me. Add to it Assets > Open C# Project – Shivam Mar 20 '22 at 12:35
6

Bro, i have the answer for you. the solution is super SIMPLE you just have to make sure that you already download these tools :

  • Unity Code Snippets by Kleber Silva
  • Debugger for Unity by Unity Technologies
  • Unity Tools by Tobiah Zarlez

which you can find them all on VSCode, after installing it, close the VSCode and reopen. That's all of it.

I've been strolling to any possible solutions I could find for the same problems as yours, but the answer is just as away as your right-hand to your mouse.

Paulusuluap
  • 61
  • 1
  • 2
  • this should be the top answer – user299709 Jul 17 '20 at 18:41
  • 5
    These extensions add some nice snippets to VS Code but do not provide full intellisense! – Kokodoko Sep 11 '20 at 16:11
  • 1
    @user299709 this should not be top answer as I too am having this situation and I have all those extensions installed and am only getting IntelliSense to show me some monobehaviour autocompletes, but things like transform or gameobject or GetComponent aren't recognized. Although I just updated my .NET to 4.8 I will probably just go download the 4.7.1 to keep the workflow going. – Technorocker Dec 01 '20 at 02:51
5

For those still struggling till this day, there's a guaranteed solution to the problem, the downside is that you can't use the .NET Standard 2.0 as your API compatibility level. Anyhow:

  • Go to Edit > Project Settings > Player, scroll down to Configuration and change your API compatibility level to .NET 4.x.
  • Go to Window > Package Manager and make sure that the Visual Studio Code Editor package is updated to the latest version.
  • Go to Edit > Preferences > External Tools and make sure you are using Visual Studio Code as your external script editor, then press the Regenerate project files button.
  • Restart Visual Studio Code, or press CTRL+SHIFT+P to open the command palette and restart OmniSharp.
ryuk
  • 143
  • 2
  • 7
4

What helped for me was to install the missing Developer SDK which was pointed out in the VS Code Output Console (OmniSharp Log).

There it said in my case was .NET 4.6 missing, after installing this (not the latest 4.8) IntelliSense worked.

https://dotnet.microsoft.com/download/dotnet-framework

Pang
  • 9,564
  • 146
  • 81
  • 122
dan_wipf
  • 141
  • 9
4

In Unity 2020 I fixed this by installing mono-devel and set 'omnisharp.useGlobalMono':'always' in settings.

P.S. I am in ubuntu 20.04 everything latest and default.

HackSlash
  • 4,944
  • 2
  • 18
  • 44
  • [This person](https://nosuchstudio.medium.com/setting-up-unity-2019-x-with-vscode-on-ubuntu-18-04-lts-a-troubleshooting-guide-75da7ff29ff5) had trouble with `mono-devel` and was able to get it working by installing `mono-complete` instead. – Gigi Jun 15 '21 at 16:52
2

I downgraded the Visual Code Editor package in Unity Package Manager to 1.20 (Its Jan 2022) and it all worked. This was a downgrade from 1.2.4. One of the versions in between may also work but it worked, so Ik left it :)

Thanks to @pang above for the idea.

Unity 2020.3.25 with Mono 6.12 installed.

Carl Last
  • 21
  • 2
1

I had the same requirement and finally found an easy solution. I just switched to another IDE, Rider provided by JetBrains. Unity supports it and vice versa.

Pang
  • 9,564
  • 146
  • 81
  • 122
akuma8
  • 4,160
  • 5
  • 46
  • 82
1

I had similar problem. I've just found the problem it's because of OmniSharp cant connect to the server properly. The solution is just open in your project Assembly-CSharp.csproj which is included some of your project settings.Then add this line of codes to the Script

<PropertyGroup>
  <DefaultItemExcludes>node_modules/**;$(DefaultItemExcludes)</DefaultItemExcludes>
</PropertyGroup>

İt worked for me. By the way if you want more detail about this https://github.com/dotnet/sdk/issues/8659

Edit: I've again that issue. I found another solution for that. First open a C# script(Can be any script doesn't matter). Then open the terminal and select OmniSharp on terminal output then wait little but do not close the script and terminal you have to keep them open, it's kind a bug I think. Give it little time. If you have an error like "Omnisharp cannot connect it take too long" I don't remember exactly what was typing on error but seems like that. Then press ctrl + shift + P and select developer reload window then open again terminal->> output->> OmniSharp Log and wait.İt works after second or third trying so 2-3 minutes.

Pang
  • 9,564
  • 146
  • 81
  • 122
DenizBey
  • 21
  • 2
1

For me the problem was working on the wrong solutions (.sln) file! (:

In the bottom-left corner of VS Code, there should be some project.sln filename. I had project-csharp.sln open instead of project.sln, so I changed it by clicking on it. In addition, I also generated all .csproj files as described here.

enter image description here

Pang
  • 9,564
  • 146
  • 81
  • 122
xjcl
  • 12,848
  • 6
  • 67
  • 89
1

For VS Code windows. I solved as below

My Installed Specifications:

  • VS Code 1.70.1
  • .NET SDK 6.0.302
  • .NET Developer pack 4.7.1
  • Unity 2022.1.12f1
  • Unity Hub 3.2.0

Steps:

  • Installed all above softwares
  • Remove any older VS Code and install above mentioned or latest
  • Open VS Code and from extensions Install C# extension only. Wait few sec
  • Close the VS Code and open Unity 3d
  • Goto Edit > Preferences > External Tools > Select Script editor as VS Code
  • Close windows and Goto Assets > Open C# project. See the output log for [fail]
  • I was having .NET devpack 4.7.1 missing issues so installed above version
  • Done

So far i have not found any intellisense issue. It's working fine

Nikita K
  • 75
  • 2
  • 11
0

If there's a .gitignore in you repository, commnet out .sln (#.sln) in .gitignore .gitignore for unity so VSCode can recognize sln file, then you'll get IntelliSense working. VSCode .sln

kangbo
  • 51
  • 2
  • 1
0

An additional idea, for anybody experiencing similar issues of IntelliSense not working for Unity 2019 scripts in VS Code. I tried most of the common solutions found on the forums but the thing that ended up fixing it for me was to just downgrade the version of the VS Code plugin in the Unity Package Manager (even though I ended up below the "verified version").

Pang
  • 9,564
  • 146
  • 81
  • 122
0

I bit the bullet and downloaded the full Visual Studio for Mac. I gave up on Visual Studio Code after a few hours of going in frustrating circles and trying several suggestions on the Unity forum and StackOverflow that didn't work.

One thing I noticed right off the bat is that the Visual Studio installation will automatically prompt you to download the necessary .NET stuff. I didn't have to run any commands to install things once Visual Studio was installed (although, I did download the dotnet and Mono installations previously for VS Code, so who knows if these were used or not...).

Once Visual Studio for Mac is installed, I went into Unity and gave Visual Studio Code the ol' boot by updating my preferences to open Visual Studio as my external editor:

  • Unity version: 2020.3
  • Unity > Preferences > External Tools > External Script Editor > Visual Studio for Mac [8.10.11]
  • I've also got Package Manager > Visual Studio Editor installed (2.0.11)

Finally, I opened my .cs file from within Unity (alternatively, you can right-click and select Open C# Project). Once Visual Studio opened:

  • Visual Studio > Preferences > Theme > Dark (we aren't barbarians...)
  • ...and then File > Open > and opened my Unity game .sln file.
  • I went to the script in question to try things out and badda-bing-badda-boom, intellisense and all my stuff worked and opened without a hitch.

Best of luck.

Danny Bullis
  • 3,043
  • 2
  • 29
  • 35
0

For Windows "The reference assemblies for .NETFramework,Version=v4.7.1 were not found" then install developer pack https://dotnet.microsoft.com/en-us/download/dotnet-framework/net471 then try exit and open vs code if not work then restart

Jeeva
  • 1,707
  • 1
  • 10
  • 7
-1

In Unity Click on Edit>>Preferences>>External Tools

Make use you select Visual Studio 2019 by browsing to location where Visual Studio is Installed

Note : Make sure you check all the checkboxes below Generate .csproj files

enter image description here

Sayed Muhammad Idrees
  • 1,245
  • 15
  • 25
-2

In Unity 2020 (on Mac, not Windows), the only solution that worked for me was to set Visual Studio (and not VSCode) as the scripts editor. You can do this by doing this in Unity: Unity > Preferences > External Tools > Select "Visual Studio for Mac" from the "External Script Editor" dropdown. Click on the script you want to edit in Unity. It should open in Visual Studio now and intelliSense should work.

edit: after that, set vscode as editor and don't regenerate the project files, it'll work. Works for me, but i need to do it on every lauch, this was all working fine like 2 months ago, ~August 2021. I am using latest unity stable version, not lts.

mcdz
  • 3
  • 3
eli-bd
  • 1,533
  • 2
  • 17
  • 35
-14

It's not a solution for your problem, but I think that there is no problem with it at all. Unfortunately, as for now IntelliSense for VS Code isn't supposed to work for Unity specific methods and functions, I believe in it.

As a kind of workaround you can use Unity code snippets extension, it'll bring some methodes to IntelliSense. The only problem for me is that it used K&R formatting, so I made my own snippet file for that.

And also maybe you noticed, but if you already have some defined Unity methodes in your script, IntelliSense will detect them.

  • I was able to get VSCode to work with Unity by following some of the solutions below. (installed Mono, ensure 'omnisharp.useGlobalMono':'always' in settings, ensure that Unity is set to use VSCode instead of auto detect and force creating all CSProj files) – Rich G May 28 '21 at 21:23