''UI' does not exist in the namespace 'UnityEngine'
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:
- Close Unity and any code editors you have open
- Make a backup of the Library folder from your project folder to your desktop
- Delete the Library folder from your project folder
- Open your project (Unity will rebuild the Library folder)
- Close Unity
- Delete the newly generated Library folder
- Move the Library folder (you backed up earlier) from your desktop back into your project folder
- Open your project
- 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 |

