How to get intellisense in Visual Studio Code for Unity functions names?
Asked Answered
D

14

57

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

Dougall answered 5/9, 2018 at 16:6 Comment(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 integrationEwer
Does this answer your question? Unity Scripts edited in Visual studio don't provide autocompleteSelfpreservation
M
39

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.

Multistage answered 9/3, 2020 at 15:16 Comment(6)
Hello there, I am having trouble understanding this solution. Delete both files means?Carrageen
Sorry for the obscurity. Assembly-CSharp.csproj and project-name.sln.Lapidate
This fixed it for me. Thank you. As of version 2019.4 the path to regenerate is Edit>Preferences>ExternalTools>Regenerate project filesPadraic
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.Abroach
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.Vilberg
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,Tinker
O
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.

Orfield answered 10/11, 2020 at 14:4 Comment(6)
Do we need .net framework for this? As far as I know, Unity is using Mono.Sandbag
Pay attention to the Dev Pack version if you dont want to waste some time like I did: 4.7.1Cynewulf
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?Operative
@Operative the dev pack is not a VSC extension, it's a library of itself. here microsoft.com/en-us/download/details.aspx?id=56119Orfield
@Sandbag That's what it says in the guide for installing VSCode for Unity code.visualstudio.com/docs/other/unityOrfield
note to self: in case Intellisense is not working it might be a problem with OmniSharp server (dot net version or whatnot)Orfield
D
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

Depraved answered 7/10, 2019 at 8:12 Comment(3)
Simply installing C# extension helped me, +1Soar
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.Gowen
installing dotnet for vs code helped me, thanks for your solution. hope others will find it usefulRoi
P
8

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

Polonium answered 11/4, 2020 at 10:47 Comment(1)
+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.Clupeid
N
7

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.

Neckcloth answered 5/9, 2018 at 17:48 Comment(0)
S
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"

Setula answered 12/10, 2021 at 11:51 Comment(2)
just remember to install MonoDevelop some howCarthage
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) properlyPhlox
R
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.

Rosner answered 14/8, 2020 at 15:43 Comment(0)
D
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)

Dominick answered 24/3, 2021 at 8:58 Comment(0)
G
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.

Gobbet answered 28/3, 2021 at 13:22 Comment(0)
O
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

Orff answered 7/8, 2021 at 18:34 Comment(0)
B
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

Bartender answered 9/1, 2022 at 17:12 Comment(0)
P
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.

Priscilapriscilla answered 1/7, 2020 at 13:27 Comment(0)
C
0

There's an official Microsoft extension in the Extension Marketplace: https://marketplace.visualstudio.com/items?itemName=VisualStudioToolsForUnity.vstuc In VSCode Extensions icon you can search Unity and found this and more tools. Hope I helped you :)

Cairo answered 25/1 at 9:15 Comment(0)
S
-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.

Sew answered 29/4, 2021 at 21:54 Comment(2)
This was not the author's question.Gaudery
okay so what is wrong with my answer? When I had the same problem I had to take these steps to finally get the autocompletion working so it can't be so wrong :|Sew

© 2022 - 2024 — McMap. All rights reserved.