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

I am doing a small course for beginners about Unity 3D here. After importing all the assets from the unity asset store, as explained in the course, I get an error that probably shouldn't be generated, that says:

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

I have already searched for this problem but I have only found answers from older versions of Unity. I tried, as some said, to reimport all the assets and to close and re-open unity but both ways seem to not work for me.

This is the first line of code from the ChinemachineStoryboard file, that the compiler indicates: public UnityEngine.UI.RawImage mRawImage;

The second one (line 32) is just a comment so i don't understand how it could affect anything, but just in case, here it is: /// <summary>Image will be cropped if necessary so that the screen is entirely filled</summary>



Solution 1:[1]

First of all Unity 2019.3.0a4 is an Alpha version. You can see this on the a in the version. b would be a Beta version which still isn't stable for production.

In short: Don't use alpha or beta versions for production. They are not stable and full of bugs and errors. You should only use them for testing the absolutely newest features .. and only for that. That's the whole purpose of having alpha and beta versions.

Rather stick to the latest stable versions! You can recognize them on the f in the version. Currently it is 2019.3.0f1


The reason here in specific is that in the newer Unity versions the entire UI and Editor GUI was completely renewed and the now "legacy" UnityEngine.UI moved to a package in the PackageManager ... thus the namespace simply doesn't exist anymore if the according UI Package is not installed for your project.

Solution 2:[2]

I ran into this error after importing an asset from the asset store.

After a lot of troubleshooting, I noticed that the asset imported a package called PackageManagerUI.

After uninstalling that package, the error went away.

I'm using Unity version 2019.3.7f1. Perhaps that package is built-in now.

Solution 3:[3]

The issue is still present in Unity 2019.3.x and MS Visual Studio Code. I solved it with these steps:

  1. open the Package manager
  2. reinstall Unity UI + TextMeshPro modules
  3. upgrade Visual studio editor package to 1.2.0
  4. close Unity
  5. delete whole Library folder in the project
  6. open Unity

I tried these steps multiple times in various order therefore I'm not able to write exact order. Feel free to experiment :)

Solution 4:[4]

I had this issue, and I tried (without success) a couple solutions found on the Unity forum.

  • The first thing I tried was rebuilding the project Library, which as the poster stated, doesn't make any sense, but a couple people said it worked, so I gave it a shot.
  • Next I tried changing the Visual Studio Code Editor package from 1.1.4 to 1.2.0, which also did not work.

Ultimately, what did solve it for me was returning from 1.2.0 to 1.1.4 (verified version), so I suspect that, in my case, uninstalling and reinstalling the Visual Studio Code Editor package would have resolved the issue.

Solution 5:[5]

I found out (after trying literally everything i have found in the internet about this problem) that the developer tools of visual studio for unity may have a problem to write the new references as in unity 2019.3 (I have upgraded a project from 2017.1.0f3 to 2019.3.0f6) they moved the UnityEngine.UI to a package.

Deleting the tools folder from C:\ProgramFiles(x86)\Microsoft Visual Studio Tools For Unity\*version folder* and after that I ran the "API Updater" in unity fixed the problem for me. (maybe you should try do that before deleting the folder - for me it doesn't work)

I work in a standalone work environment so I can't let the NuGet Package Manager take care of it automatically because there is no internet. Hopes this is helpful in some way!

Solution 6:[6]

Adding my answer in April 2021, Unity version: 2020.3.2f1. I tried a number of things including removing the Unity Collaborate package. What I ended up finding was somehow in Visual Studio (Mac) some code had been added to the end. I'm not sure when or how it happened. It could have been when typing too fast and accidentally selecting some intellicode choice or something that happened when my mouse when on the fritz and I had to replace the batteries, but the following code appeared at the end of the script and bugged it. Removing it fixed everything.

    public class Text
    {
        public string text { get; internal set; }
    }

Solution 7:[7]

This is due to one issue. UnityUI.dll is present in the location of Library/ScriptAssemblies(library of your project).

If you will open your Assembly-CSharp.csproj ,search

<Reference Include="UnityEngine.UI">

if it is not present there add

For Mac Users

<Reference Include="UnityEngine.UI">
<HintPath>/Users/[Path to your current project]/Library/ScriptAssemblies/UnityEngine.UI.dll</HintPath>
</Reference>

For Window Users

<Reference Include="UnityEngine.UI">
<HintPath>Library\ScriptAssemblies\UnityEngine.UI.dll</HintPath>
</Reference>

Solution 8:[8]

Just open the Solution Explorer of your IDE and go to References and look for UnityEngine.UI, there must be a warning sign over it, just click on it and it will be resolved. if there's no UnityEngine.UI you must add it yourself.

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
Solution 2 schmosef
Solution 3 David Rysanek
Solution 4 Bryon Nicoson
Solution 5
Solution 6 VasoVagal
Solution 7
Solution 8 Alireza Jamali