The type or namespace name 'UI' does not exist in the namespace 'UnityEngine'

The error

Unnecessary using directive. [Assembly-CSharp]csharp(CS8019)
The type or namespace name 'UI' does not exist in the namespace 'UnityEngine' (are you missing an assembly reference?) [Assembly-CSharp]csharp(CS0234)

Appears sometimes after updating project unity version or after reopening project.
I use VSCode. To fix this. I need every time to:

  1. Delete .sln in explorer
  2. Change default code editor to VS2019
  3. Open code from the editor menu with VS
  4. Wait untill libraries will be resolved
  5. Change editor back
  6. Open project code with VSCode.
1 Like

Did you find any other fix to this? I don’t want to install VS just to prevent this error.

It’s likely the above can simply be accomplished straight from Unity with Assets → Open C# Project. That resolves like 99% of issues quite cleanly, assuming you have your software installed properly.

Here’s my standard blurb for fixing Visual Studio.

This may help you with intellisense and possibly other Visual Studio integration problems:

Sometimes the fix is as simple as doing Assets → Open C# Project from Unity. Other times it requires more.

Also, try update the VSCode package inside of Unity: Window → Package Manager → Search for Visual Studio Code Editor → Press the Update button

Also, this: No suggestions in Vscode

And here are some more notes:

UnityEngine.UI is now a package:

Annoying possible issue circa October 2021:

I just installed VS and followed your steps, but still have the issue.

Edit: this was in reply to the original post.

Thanks for replying.

I’m on latest unity (2021.2.3f1). Latest packages for UI (1.0.0), VS Code. Everything works fine, intellisense etc. The only problem I have is that somehow the reference to UnityEngine.UI isn’t being picked up by VS code somehow. This means I get lots of warnings about any script files that references UI stuff.

I’ve tried reimporting assets in unity. I’ve tried the OP steps to install VS, then regenerate for VS. I’m not familiar with using VS but I could open a script, see now errors and UI code completion seemed fine.

If you google for the issue, there are so many results, so this must be a common problem, I’m just not finding a fix that works.

Maybe I should start a new post with all the details.

I just downgraded the VS Code package (closed unity, edited the manifest.json) - went to 1.1.2 by random. Reloaded unity. Deleted sln and csproj. Then I regenerated proj files in unity (where you pick external editor) and opened vs code. All working fine.

I think there’s a bug in newer versions of the vs code cs proj generation. I’ll see if I can report a bug somewhere…