2

The issue is VS code doesn't see UnityEngine.UI library.

I had this issue before and I solved like it this: I changed the code editor in preferences to Visual Studio, regenerated files and launched c# project. On the start, vs created needed .csproj files and then I closed vs and changed it back to vs code and it workeed.

However, now I am working on another project and I encountered same issue, I tried the method I described above but it didn't work.

Any ideas?enter image description here

  • 1
    Another project... on the same computer? I wonder if you're missing the Unity tools. – Chuck Sep 21 '21 at 16:57
  • @Chuck yes same pc, everything is the same. All necessary tools are present. Intellisense works fine. – Eldar Sacramento Sep 21 '21 at 17:12
  • You can disable packages in Unity, UI is one of those. You can verify if you have a reference in your *.sln. If you are using asmdef you might need to link UnityEngine.UI.dll to your asmdef – Tomasz Juszczak Sep 22 '21 at 10:50
  • @TomaszJuszczak could you tell me please how to link UnityEngine.UI.dll to my asmdef , and also I am not sure if I use it. How can I check it I do? Regarding the first part, I can't uninstall UI package because Text Mesh Pro and URP relies on it. – Eldar Sacramento Sep 23 '21 at 11:14
  • I had the exact same issue after updating one of my project from 2020.3.15 to 2020.3.19 (lts) – shrekshao Oct 09 '21 at 16:09

3 Answers3

0

So, after days of tinkering and trying different solutions I found on the internet I finally found out how to solve it (all by myself).

Switch to VS and make sure it detects the UnityEngine.UI library. Then don't close VS, switch to VS Code, don't hit "regenerate files", launch c# project, enjoy!

  • This did work for me. Unfortunately it seems I need to do this everytime I open project. (if I switch back to choose vscode instead visual studio as the external tool). But good to have a workaround – shrekshao Oct 09 '21 at 16:13
  • @shrekshao I found a permanent solution. Just use Rider. It's waaay better and without cancerous glitches. – Eldar Sacramento Oct 09 '21 at 20:24
0

These steps covered several possible issues:

https://stackoverflow.com/a/70977258/6046022

(just an overview, follow the link for the complete steps)

  1. downgrade VSC package
  2. re-install Unity UI
  3. regenerate files
Saleh Hosseini
  • 482
  • 4
  • 11
0

I had this problem and it was driving me crazy. Tried a 100 ways.

What helped for me in the end:

  1. Go into package manager
  2. Select the Unity registry
  3. Search for "Visual Studio Code Editor"
  4. Update it.
  5. I restarted unity and vscode, and it just worked :)

Hope this helps someone!