user11796379
user11796379

Reputation:

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>

Upvotes: 6

Views: 27575

Answers (12)

Muhammad Abdullah
Muhammad Abdullah

Reputation: 1

Import Unity UI package in Windows->package Manager->Unity Registry-> Unity UIenter image description here

Upvotes: 0

Moeed Ahmed
Moeed Ahmed

Reputation: 612

I was porting an old project to a newer version of Unity and after trying all the provided solutions with no success, I simply installed the Unity UI package from the Unity Registry Solved My Problem!

Upvotes: 0

Somesh Bhardwaj
Somesh Bhardwaj

Reputation: 1

Please add Ui pacakage from package manager enter image description here

Upvotes: 0

Phuc
Phuc

Reputation: 155

I see this problem maybe from too long time ago. But I would like to share my solution if someone need it and the same case with me.

Basically, the problem happen right after I remove old version Admob and import new version and the problem show up. After doing many way to solve and the error still there. I do these simple step

  1. Remove the new Admob version -> error gone
  2. Import new Admob version again -> fixed

I am not sure why or maybe in my first import having some process not work. I believe it can be the same for other plugin/extension in import process. So just delete new one and import again

Hope it help

Upvotes: 0

noobgamedev
noobgamedev

Reputation: 1

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>

Upvotes: 0

VasoVagal
VasoVagal

Reputation: 31

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; }
    }

Upvotes: 0

Alireza Jamali
Alireza Jamali

Reputation: 317

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.

Upvotes: -1

sagi dadon
sagi dadon

Reputation: 11

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!

Upvotes: 0

Bryon Nicoson
Bryon Nicoson

Reputation: 943

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.

Upvotes: 0

David Rysanek
David Rysanek

Reputation: 979

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 :)

Upvotes: 6

schmosef
schmosef

Reputation: 344

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.

Upvotes: 0

derHugo
derHugo

Reputation: 90580

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.

Upvotes: 3

Related Questions