''UI' does not exist in the namespace 'UnityEngine'

I've tried a lot of things already but nothing worked. enter image description here

I've already reimported, deleted, and reinstalled stuff. I'm using unity 2019.3.0f6 and vs code 1.42.1.



Solution 1:[1]

I used Visual Studio Community 2017 and had the same problem (using Unity 2019.3.12f1). After trying a lot of things (none worked), including the answers provided here, what finally worked for me was the following:

  • Install Visual Studio Community 2019 (I also selected "Game development with Unity").
  • In Unity select this one as the "External Script Editor" (Edit -> Preferences... -> External Tools).
  • Fix broken references between projects within the solution in Visual Studio by first removing the references and then adding them again (Project -> Add Reference...). (Solution to a new problem that arose after switching to Visual Studio Community 2019).

This last step has to be done again when Unity regenerates .csproj files. I found that the <ReferenceOutputAssembly>false</ReferenceOutputAssembly> tags in the generated .csproj files is responsible for this (after re-adding references in Visual Studio, these tags are removed when saved). I verified that manually removing those lines from the .csproj using a text editor also works. I'm not sure if this setting can be managed somehow within Unity.

Solution 2:[2]

Remove the Library folder from the project and open it again to resolve this issue.

This will trigger a full reimport and new metadata will be created for a lot of stuff. It's probably not an issue for most, but on a big project, it can take a long time to reimport everything!

In case you want to take a safer approach, do the following:

  1. Close Unity and any code editors you have open
  2. Make a backup of the Library folder from your project folder to your desktop
  3. Delete the Library folder from your project folder
  4. Open your project (Unity will rebuild the Library folder)
  5. Close Unity
  6. Delete the newly generated Library folder
  7. Move the Library folder (you backed up earlier) from your desktop back into your project folder
  8. Open your project
  9. UnityEngine.UI should be fine now

Hope this helps!

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Bert Regelink
Solution 2 Lorenzo Goldoni