3

VS Code IntelliSense does not work with Unity. Why?

I am using Unity with VS Code. When I type I do not get any suggestions which are related to Unity. E.g. I am not getting the gameObject suggested once I type this.:

enter image description here

Another example is that I can not go to the MonoBehaviour definition:

enter image description here enter image description here

I saw this question. So, I checked that all of the extensions recommended in the answer are installed:

enter image description here

The extensions installation did not help. Could someone help with the issue, please?

I am using the Unity 2019.3.2f1.

If in Unity Editor I go to the Window - Package Manager - search for Visual Studio Code Editor I see it is there:

enter image description here

Actually I can not see the definition even for System. So, I believe there should be something wrong on the VS Code side:

enter image description here

Also, I followed the video. It did not help. Under the video there is the comment:

For anyone still cannot get the autocomplete to work, try installing the ".net framework 4.7.1 developer pack".

In my case, I am using Unity 2019.1.2, and I installed dotnet core 2.2 which comes with ".net framework 4.7.2.". Apparently Unity 2019.1.2 requires framework 4.7.1. You can find which .net framework version is required by checking the Assembly-CSharp.csproj file

I followed the comment suggestion. I checked what version is specified in my case in the TargetFrameworkVersion. It is 4.7.1. So, I downloaded the 4.7.1. While installing the version it told me that it is already installed and whether or not I would like to reinstall it. I reinstalled it and still it did not help.

Community
  • 1
  • 1
qqqqqqq
  • 1,831
  • 1
  • 18
  • 48
  • this might help you https://stackoverflow.com/questions/42597501/autocompletion-not-working-in-visual-studio – this.girish Feb 22 '20 at 17:47
  • @this.girish, thank you for your comment, but I am asking about VS Code, not about VS. – qqqqqqq Feb 22 '20 at 17:49
  • oh my bad! check https://forum.unity.com/threads/cant-get-vscode-to-work-properly-with-unity.538224/ link and it is answered by user Kurolox. – this.girish Feb 22 '20 at 17:56
  • What is your unity version? – Hamid Yusifli Feb 22 '20 at 17:58
  • @this.girish, thank you. Just checked, the `.sln` file was generated successfully and was at the root of my project all the time. So, I supposed I am missing something different here. – qqqqqqq Feb 22 '20 at 17:59
  • Does **Window-> Package Manager-> Visual Studio Code Editor** package exist? – Hamid Yusifli Feb 22 '20 at 18:07
  • @0xBFE1A8, yes it does exist. I updated my question. I believe that the issue is on the VS Code side. – qqqqqqq Feb 22 '20 at 18:17
  • @0xBFE1A8, it seems I was able to fix the issue. I went to **Edit** - **Project Settings** - **Player** - **Other Settings** - **Configuration** - **Api Compatibility Level**. Then I changed it from `.NET Standard 2.0` to `.NET 4.x`. Then I reopened Unity, changed it back (to preserve the API restriction) and reopened Unity. And now the suggestions work as expected. Except for a few warnings I am getting on script opening (I will create a different question for this). Thank you for your help. – qqqqqqq Feb 22 '20 at 18:51
  • @0xBFE1A8, [here](https://stackoverflow.com/questions/60355637/omnisharp-in-vs-code-produces-a-lot-of-warnings-about-a-unity-project-why) is the question. If you will have time, could you, please, take a look at it? – qqqqqqq Feb 22 '20 at 18:55
  • @qqqqqqq Glad that you found the issue! Please post it as an answer (you can answer your own questions here, and are in fact encouraged to do so). – Ian Kemp Feb 22 '20 at 18:56
  • 2
    @IanKemp, @0xBFE1A8 tried to help me. I think it would not be fair if he get nothing for it. So, don`t you think it would be a good idea if he posts the answer? Actually I see it very often here on SO when someone spends time trying to help (and actually helping) in comments and is not shown gratitude afterwards. It may discourage that someone to spend time and help next time. Are you definitely sure that I should post my answer? – qqqqqqq Feb 22 '20 at 19:01
  • 1
    @qqqqqqq It's really great that you're thinking about someone who helped you, but at the end of the day, you are the one who found the solution. My suggestion would be to post the answer yourself, and in it mention that 0xBFE1A8's suggestion on what to look at helped you find a fix. I feel like that's fair to all. – Ian Kemp Feb 22 '20 at 19:06
  • Might help: https://stackoverflow.com/a/62949390/13374682 – Domotor Zsolt Mar 06 '22 at 15:52
  • Out of curiosity, are there advantages to using VS Code with Unity over VS Community Edition? – Sven Viking Apr 06 '22 at 12:36
  • 1
    @SvenViking, crossplatform – qqqqqqq Apr 06 '22 at 19:54

1 Answers1

12

It seems I was able to fix the issue. I went to Edit - Project Settings - Player - Other Settings - Configuration - Api Compatibility Level. Then I changed it from .NET Standard 2.0 to .NET 4.x. Then I reopened Unity, changed it back (to preserve the API restriction) and reopened Unity. And now the suggestions work as expected. Except for a few warnings I am getting on script opening (here is the question which is related to the warnings).

qqqqqqq
  • 1,831
  • 1
  • 18
  • 48