55

I am following a tutorial about Unity and I see that the instructor has intellisense when writes the method's name.

However I have only intellisense with classes and variables, I mean Unity classes like Rigidbody and my own variables.

enter image description here

I have also read: Autocompletion not working in Visual studio

How to enable intellisense in Visual Studio 2017 for Unity

Magnetron
  • 7,495
  • 1
  • 25
  • 41
Yone
  • 2,064
  • 5
  • 25
  • 56
  • 2
    VS Code is not VS, VS ties directly into the .net framework and so can provide intellisence from the entire framework, Code is language and framework independent , you will need to find an appropriate Extension for unity (i've not used it for unity so can't recommend one) either that or switch to VS community then you'll have the full VS integration – MikeT Sep 05 '18 at 16:19
  • Does this answer your question? [Unity Scripts edited in Visual studio don't provide autocomplete](https://stackoverflow.com/questions/42597501/unity-scripts-edited-in-visual-studio-dont-provide-autocomplete) – amitklein May 11 '21 at 07:39

13 Answers13

38

Old question, but I had the same problem just recently.

There must have been an issue in your Assembly-CSharp.csproj or project-name.sln files. Most likely to be the .csproj file. If you take a look at it, you will see various references to .dll files.

You can tell Unity (my version: v2019.2.20f1) to create these for you by enabling Edit > Preferences > Generate all .csproj files.

 1. Delete both files.
 2. Enable .csproj file generation.
 3. Double click on a script in Unity.

This fixed my issue.

  • Hello there, I am having trouble understanding this solution. Delete both files means? – Ashik May 12 '20 at 22:42
  • Sorry for the obscurity. Assembly-CSharp.csproj and project-name.sln. – Mehmet Fırat Koloğlu May 13 '20 at 11:32
  • 11
    This fixed it for me. Thank you. As of version 2019.4 the path to regenerate is `Edit>Preferences>ExternalTools>Regenerate project files` – Jon Plotner Jun 28 '20 at 00:41
  • I solved it by choosing the External Script Editor to Visual Studio (in Edit > Preferences > External Tools). The choice was "Open by file extension," and that choice didn't create the .csproj files. – redcurry Oct 26 '20 at 22:50
  • Unity 2020.1.11f1 (with Visual Studio Code Editor 1.2.3) on Ubuntu 20.04. On vs code, I also needed to change C# extension settings: "Omnisharp: Use Global Mono" to "always", after installing latest mono on my system. – dvlcube Nov 15 '20 at 00:43
  • 3
    In newer unity editors (version 2020 at least) i had to change in the `Edit->Preferences->External Tools->External Script Editor` from `Open By Script Extension` to `Visual Studio Code`. This updated the preferences windows with more check boxes. I left them all unchecked (default). I then clicked `Regenerate project files` button, – xtreampb Aug 21 '21 at 14:23
29

I would really like to clear things up a bit for everyone trying to get Intellisense working with Visual Studio Code.

First of all I am writing this for Unity 2019.4.14 (edit: also for 2020.3 and 2021.3).

These are the things you MUST do for this to work:

  1. You need Visual Studio Code (duh)
  2. You need .NET SDK. I don't think it matters which version, latest is the best I guess. Make sure you install the SDK, not the runtime.
  3. Check if you have .NET SDK installed by typing dotnet in the VSCode terminal.
  4. You also need The .NET Framework Dev Pack because otherwise VSCode is going to be throwing this error:

The reference assemblies for .NETFramework,Version=v4.7.1 were not found. To resolve this, install the Developer Pack (SDK/Targeting Pack) for this framework version or retarget your application.

  1. In VSCode search for the 'C# for Visual Studio Code' extension and install it
  2. In Unity go to Package Manager and install Visual Studio Code Editor. This will enable Unity to generate proper project files for VSCode. (might be already installed)
  3. In Unity go to Edit -> Preferences -> External Tools and choose VSCode from the dropdown (could be listed as code.cmd) and after you choose it tick all the checkboxes you want in the Generate .csproj files for section. I checked Embedded Packages, Local Packages, and Packages from unknown sources. Click 'Regenerate project files'
  4. Open any C# file from Unity and you should be good to go. (you might need to restart VSCode after regenerating project files in order for this to work)

Now, what about Unity Code Snippets and Debugger for Unity extensions? Well these are useful helper extensions but they have nothing to do with Intellisense. The first is for quickly typing common Unity patterns and the second is for showing Unity Debug warnings and errors as you type instead of saving and going back to Unity and reading the console.

Hope this was of any help.

p.s. One more note: Visual Studio Code depends on the solution files we generate through Unity for Intellisense to work. This is important because you have to add the entire project folder to VSCode workspace and not just Assets folder or your Scripts folders. If you add only the Assets folder to VSCode it won't be aware of those solution (.sln) files. If you open scripts through Unity it will probably work regardless.

  • Do we need .net framework for this? As far as I know, Unity is using Mono. – Terence Dec 14 '20 at 02:58
  • 1
    Pay attention to the Dev Pack version if you dont want to waste some time like I did: 4.7.1 – Baboo Feb 17 '21 at 22:04
  • There doesn't seem to be any .Net Framework Dev Pack, .Net Developer Pack or anything similar in the VSC extensions. There is a .Net Core Extension Pack, but you said that's not it. There is a Unity Dev Pack. Is that what you meant? – nwp Jun 26 '21 at 10:18
  • @nwp the dev pack is not a VSC extension, it's a library of itself. here https://www.microsoft.com/en-us/download/details.aspx?id=56119 – Aleksandar Ruseski Aug 30 '21 at 20:20
  • @Terence That's what it says in the guide for installing VSCode for Unity https://code.visualstudio.com/docs/other/unity – Aleksandar Ruseski Aug 30 '21 at 20:24
  • note to self: in case Intellisense is not working it might be a problem with OmniSharp server (dot net version or whatnot) – Aleksandar Ruseski May 25 '22 at 10:36
12

Although the answer by Alex Myers is helps, its not 100% right. Unity Snippets does give you some snippets, and the illusion of typeahead, it's not actually intellisense.

For true intellisense you need to:

More information can be found here: https://code.visualstudio.com/docs/languages/dotnet

You can test you have dotnet installed by typing dotnet into the terminal within VSCode.

Note In the image below how I get a full method signature, reference counts, and the yellow hint globe. These are only available when using dotnet + extension (and not available when using the snippets)

enter image description here

Chris
  • 54,599
  • 30
  • 149
  • 186
  • 2
    Simply installing C# extension helped me, +1 – DCON Nov 10 '19 at 19:15
  • For me, I installed C# extension, but the .net version was not correct (I had several older versions that's installed with Visual Studio). Also check the console to make sure all the versions are correctly installed. – GoldenArcher Oct 20 '21 at 03:15
  • installing dotnet for vs code helped me, thanks for your solution. hope others will find it useful – Nilesh Singh Dahiya Nov 09 '22 at 19:25
7

Note: my solution does not solve intellisense to function names, but this was the first question that come in fixing intellisense more generally in VSCode.

I needed to update the VSCode package in unity.

In Unity, click Window, then Package Manager, then look for Visual Studio Code Editor. Expand it by pressing triangle, and upgrade to the latest version (for me, it was 1.2.0. I restarted VSCode and it worked.

v1.1.4 had a bug that caused this problem, and was not fixed for about 3 months. It is still the default package installed with a new default project, so you have to change this package version to 1.2.0 in every new project, until they update it.

Screenshot of package manager with V1.2.0

Ben Butterworth
  • 22,056
  • 10
  • 114
  • 167
  • 2
    +1 This was the issue for me; I updated from 1.2.0 to 1.2.1 and that fixed the Intellisense issues for me. – Chris Jang Jun 08 '20 at 01:11
6

Check out the guide for Unity Development with VS Code. They recommend a few extensions:

I believe the Unity Snippets extension is what you are looking for.

Alex Myers
  • 6,196
  • 7
  • 23
  • 39
5

For anyone having the same problem on a Mac, try setting this value in your .vscode/settings.json (or in the user settings instead of the workspace settings)

"omnisharp.useGlobalMono": "always"

Kheder
  • 203
  • 3
  • 9
  • just remember to install MonoDevelop some how – strider May 15 '22 at 23:19
  • This worked for me on Pop_OS! 22.10. I found the setting in VSCode Settings named **OmniSharp: Use Modern Net** - I unticked the box and restarted VSCode, which installed a mono version of OmniSharp, which now loads in all the project references (and therefore Intellisense) properly – Samuel Slade Jul 18 '22 at 15:41
2

Intellisense is a pure workflow of .Net Environment. So, you need to have .Net 'Developer pack' (not Runtime) installed on your system as it installs all three necessary components below:

  1. .Net framework
  2. .Net Target pack
  3. .net SDK

reference link: https://dotnet.microsoft.com/download/visual-studio-sdks

It is directly installed to a system admin-accessible path, so no need setting it up. Now, you have to tell VS Code which .Net version to use (whichever you have installed). Your Unity project will have these two files in the root directory:

  1. Assembly-CSharp.csproj
  2. Assembly-CSharp-Editor.csproj

In these both files search for line (probably 16):

<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>

Edit version that you had just installed (I had 4.8). Then reopen VS Code. Now everything should work fine.

Akshay Gaikwad
  • 111
  • 1
  • 4
2

For me just in Unity, Edit/Preferences/External Script Editor, and changed it to My_Install_Location\Microsoft VS Code\Code.exe (maybe hit Regenerate Project Files)

not_overrated
  • 115
  • 10
2

Sorry, I don't have good English, but I'll show you what worked for me.

I opened the C # script in Visual Studio Code and looked for the Assembly-CSharp.csproj file, then, on line 16, I changed the following:

<TargetFrameworkVersion> v4.5 </TargetFrameworkVersion>

For:

<TargetFrameworkVersion> v4.5.1 </TargetFrameworkVersion>

This solved the Intellisense issue.

1

I found another solution since none of the other solutions were working for me and i was searching for hours.(07/08/2021):

I got the feeling i found the solution for a lot of people since i reinstalled windows recently and simply downloaded everything needed to start without other problems.

I got the same error with .NET, .NET Core or .NET Framework, here are some screenshots of the errors:

Error popup

Error output

In the error output, it says to install the Developer Pack for this framework version. You can find the version in the .csproj file:

enter image description here

By installing the .NET Framework of this version on the dotnet microsoft site: .NET Framework download list i fixed the error after reloading VSCode and got my Intellisense working for Unity.

TLDR: My fix was too install .NET Framework version 4.7.1

1

If you still can't enable IntelliSense, make sure you have VS Code opened in the same directory as the .sln file (I had mine opened deeper in the Assets before).

Source: https://code.visualstudio.com/docs/other/unity

Jack
  • 11
  • 2
  • 2
0

Though the question is 2 years old, the problem pops up occasionally, just like happened to me.

I had the issue myself, so this one is possibly the first that should be checked.

  • "Install .NET Framework 4.6 Targeting Pack"

WHY?

First of all, I work with dotnet core, not the standard, so I don't have standard libraries installed on my computer. When I started trying Unity, and VS Code with it, this was the missing part I wasn't aware of.

When I hit the issue, I searched the net a while and see this question. Took me another while to notice this framework sentence in "Enabling code completion" section of VS Code and Unity page. So I tried and now I am happy I tried.

Just don't forget you need to restart at least VS Code to get the intellisense working.

PS: Framework version may, and will most possibly, be changed depending on what year we are in, and which versions we use. So if "4.6" is not working then you probably need another version.

PS2: If it is Mac you are looking for, follow the same link above and find the same section I mentioned above to get a link for .NET SDK.

Yılmaz Durmaz
  • 2,374
  • 12
  • 26
-2

Follow these steps:

  1. Go into your Unity project.
  2. Go to Edit.
  3. Go to Projects preferences.
  4. Go to External tools.
  5. In line "External Script Editor" you have to change to "Visual Studio Cummunity 2019..."

then it should work.

Joe Mayo
  • 7,501
  • 7
  • 41
  • 60