Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

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

Discussion in 'Scripting' started by Tom-Red, Apr 19, 2016.

Thread Status:
Not open for further replies.
  1. Tom-Red

    Tom-Red

    Joined:
    Jun 9, 2013
    Posts:
    15
    So! Literally all I have done that is causing this issue is the following:


    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.UI;
    3.  
    4. public class GameMode : MonoBehaviour {
    5. }
    I have only added this using statement to the script, and it is throwing an error.

    Code (CSharp):
    1. using UnityEngine.UI;
    What is going on here, and how do I fix it? This seems like some inherent problem with the engine not being able to fetch the dlls or something.

    The error is as follows:

    Severity Code Description Project File Line Suppression State
    Error CS0234 The type or namespace name 'UI' does not exist in the namespace 'UnityEngine' (are you missing an assembly reference?) VillageClicker.CSharp D:\Games\Unity Games\Casual\VillageClicker\Assets\TavernProject\Scripts\GameMode.cs 2


    I would greatly appreciate any helpful advice. :)

    P.S I have already tried Assets -> Reimport All but to no avail.
     
    KokodokoGames likes this.
  2. Kalladystine

    Kalladystine

    Joined:
    Jan 12, 2015
    Posts:
    227
    From the solution explorer of your IDE (MonoDevelop/VisualStudio/whatever you use) check the References.
    If there's no UnityEngine.UI -> add it (process will differ depending on IDE).

    Either way - did you change any settings recently? It should be added by default unless you were importing a project that had it explicitly removed.

    Edit: added sample screenshot from MonoDevelop
    upload_2016-4-19_23-13-46.png
     
  3. Tom-Red

    Tom-Red

    Joined:
    Jun 9, 2013
    Posts:
    15
    Hey! Thanks for the quick response!

    UnityEngine.UI already exists in the References.

    upload_2016-4-19_23-14-30.png
     
  4. Tom-Red

    Tom-Red

    Joined:
    Jun 9, 2013
    Posts:
    15
    This issue still has not been resolved. Would appreciate any additional input as to what might help fix this! :)
     
    KokodokoGames likes this.
  5. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    This is odd. What version of Unity are you using?
     
  6. Tom-Red

    Tom-Red

    Joined:
    Jun 9, 2013
    Posts:
    15
    The project was created in Unity v5.3.2 (I believe) and I just updated to v5.3.4 yesterday.
     
  7. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    That rules that out. Occasionally we get people who can't find it in 4.5.

    Tried turning it off and back on again? Sometimes restarting Unity and VS helps.
     
    LarStudio likes this.
  8. Tom-Red

    Tom-Red

    Joined:
    Jun 9, 2013
    Posts:
    15
    Yes. Unfortunately no luck! I wonder if something went wrong in the hotfix update. Perhaps I'll try a reinstall of the engine when I get home today. :)
     
  9. Tom-Red

    Tom-Red

    Joined:
    Jun 9, 2013
    Posts:
    15
    Looks like if I create new projects, those projects work fine with importing the UnityEngine.UI library. Very strange! I suppose I'll just remake the project and pull the files over. Case closed, sort of.
     
  10. RiQQ92

    RiQQ92

    Joined:
    Apr 20, 2016
    Posts:
    5
    I had the same problem, the problem came on my case from the unitys created 'Library' folder, which is at the root of your project. It should be safe to remove without any care but i suggest to make backup before doing so. Unity will just regenerate it when you reopen it (Heavily suggest to close unity before removing this folder).
     
  11. LarryTheBrave

    LarryTheBrave

    Joined:
    Nov 20, 2016
    Posts:
    24
    Apparently they replaced UI with UIElements. UnityEngine.UI.Text replace with UnityEngine.UIElements.TextElement and then the error should go away.
     
    MixerTrixer likes this.
  12. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    7,144
    This post was 3 years ago...and it is still UnityEngine.UI.Text

    UIElements is for editor UI.

    https://docs.unity3d.com/Manual/UIToolkits.html
     
    reggie5538 likes this.
  13. genrysss

    genrysss

    Joined:
    Mar 26, 2018
    Posts:
    21
    Remove Library folder from Project and open Project again resolved this issue.
     
  14. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    Very good advice. If in doubt, delete the library.
     
    Marijenburg likes this.
  15. MadeFromPolygons

    MadeFromPolygons

    Joined:
    Oct 5, 2013
    Posts:
    3,877
    Obviously anyone coming here reading this should factor in that doing this will trigger a full reimport and new metadata being created for a lot of stuff. Probably not an issue for most, but on a big big project that can be a long time reimporting, so try to make this your last port of call when troubleshooting!
     
  16. kdubnz

    kdubnz

    Joined:
    Apr 19, 2014
    Posts:
    177
    Why would you make the thing most likely to resolve the issue the "last port of call" ?
     
  17. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,531
    For exactly the reason GameDevCouple_I mentioned. In a large project, it can hours to rebuilt the Library folder. Depending on the issue, a quicker solution like this might be preferable.
     
    MuhammadAhmadYousaf likes this.
  18. gatzkerob

    gatzkerob

    Joined:
    Jan 19, 2020
    Posts:
    5
    Here's what worked for me:

    Note that removing the Library folder permanently (as someone else suggested) will remove all objects from your scene. But using this method will save them:

    So..
    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. Open one of your scripts
    10. UnityEngine.UI should be fine now

    Not sure why this works or if it will have any effect on the rest of your project. My project was fairly small and I didn't see any problems afterwards.

    Perhaps someone with more knowledge could point out any problems with this method?
     
  19. Azamorn

    Azamorn

    Joined:
    Oct 11, 2016
    Posts:
    1
    As weird as this approach is, this helped me fix my problem.
    I am working on Linux in Visual Studio Code for what it's worth.

    For whatever reason the issue started happening right after I worked some more on the Scene
     
    Last edited: Feb 18, 2020
  20. edwiz7

    edwiz7

    Joined:
    May 29, 2016
    Posts:
    4
    Deleting the Library folder didn't fix it for me.

    What worked was just updating the Visual Studio Code Editor package in Package Manager from 1.1.4 to 1.2.0.
     
    MrPoofyWaffle, mbry0nic and Spidlee like this.
  21. AmBeam

    AmBeam

    Joined:
    Dec 26, 2012
    Posts:
    5
    It worked for me! Thanks!
     
  22. Masiorama

    Masiorama

    Joined:
    May 1, 2017
    Posts:
    1
    Same here, it worked what gatzkerob suggested.

    Edit: nope, after a few seconds the problem got back... :(
     
  23. Arunsoman

    Arunsoman

    Joined:
    Mar 23, 2018
    Posts:
    1
    After Importing Firebase Analytics package I am getting this error. I can't solve this
    Please help me guys
     
  24. schmosef

    schmosef

    Joined:
    Mar 6, 2012
    Posts:
    851
    Just figured this out for myself.

    I started getting this error after importing an Asset from the Asset Store.

    Eventually, I noticed that the asset imported a package called PackageManagerUI.

    I uninstalled that package and the errors went away.

    I'm using Unity version 2019.3.7f1. Perhaps that package is built-in now.
     
    mbry0nic likes this.
  25. joseGuate97

    joseGuate97

    Joined:
    Mar 1, 2018
    Posts:
    55
    I was trying to add an external dll in my assets folder. The original package came with other files other than the .dll such as a .nupkg, for example. Not entirely sure if that was the problem, but adding the .dll file only seemed to be what finally worked.
     
    mbry0nic and schmosef like this.
  26. Kuroro95

    Kuroro95

    Joined:
    Apr 11, 2020
    Posts:
    2

    Thanks ! Worked for me after but not immediately. I had to reopen it multiple times... Don't know why.
     
  27. iPLEOMAX

    iPLEOMAX

    Joined:
    Feb 16, 2014
    Posts:
    17
    Alright so I had this issue (both Visual Studio 2017 and VSCode) and didn't want to delete the library folder because its a fairly sized project.

    I solved it by doing the following (for Unity 2019.2.3f1):
    1. Uninstalled the Visual Studio Code Editor Package then upgraded to latest version of it using Window > Package Manager.
    2. Switched to Visual Studio Code from Edit > Preferences > External Tools
    3. Opened VSCode and switched to output window for OmniSharp. It told me specific .NET framework was missing and needed to install it. I went to the provided link and installed the EXACT version of .NET developer framework.
    4. Waited for install to finish, restarted Unity and VSCode.

    Everything started working normally.

    EDIT: Oh and don't forget to install C# and Unity Debugger addons for VSCode first.
     
    Last edited: Apr 26, 2020
  28. SamohtVII

    SamohtVII

    Joined:
    Jun 30, 2014
    Posts:
    366
    Wow I actually was going through these steps thinking how dumb this was and how it won't work (Was at my wits end). Left this page reopened unity and there it was. Had to come back to this page to give you your kudos. Thanks
     
    AsclepiiusUnknown likes this.
  29. eLalexGame

    eLalexGame

    Joined:
    Mar 27, 2020
    Posts:
    2
    Hello guys, I have this problems in my visual studio code and any solutions did work for me please help me I can't progress in my script :(
     
  30. eLalexGame

    eLalexGame

    Joined:
    Mar 27, 2020
    Posts:
    2
    i have solve my problem, I have start the project with a version of unity 2017 and I re start the project files with the 2019.3.10f1 and its good
     
  31. gigazelle

    gigazelle

    Joined:
    May 6, 2017
    Posts:
    10
    You are my hero. This worked flawlessly for me. Thanks so much!!
     
    iPLEOMAX likes this.
  32. MaxGuernseyIII

    MaxGuernseyIII

    Joined:
    Aug 23, 2015
    Posts:
    315
    This is a prime argument for source control. I got this problem and spent a few minutes trying to win then thought to myself "Enough of this. Let's take off and nuke the entire site from orbit."

    One delete and one get-latest, the problem is fixed.
     
  33. Musahan17

    Musahan17

    Joined:
    Aug 9, 2020
    Posts:
    5
    I had "using UnityEditor.UIElements;" on my import list and I deleted this line,now it works.
     
  34. kubakakauko

    kubakakauko

    Joined:
    Nov 22, 2018
    Posts:
    1
    Uninstalling Unity Collaborate from the Package Manager worked for me
     
  35. Bailym

    Bailym

    Joined:
    Dec 30, 2019
    Posts:
    1
    I was trying to create a Text variable in a script. Turns out i needed to change the import from Unity.UI to UnityEngine.UI.
     
  36. simonseo

    simonseo

    Joined:
    Oct 29, 2020
    Posts:
    1
    Another suggestion:

    I was running into similar problems in Unity 2019.4.9 (MacOS, VSCode). I fixed it like so:

    1. go to Unity > Preferences > External Tools
    2. check everything in the "Generate .csproj files for" list
    3. click "Regenerate project files".
    4. restart VSCode
     
  37. apospraf

    apospraf

    Joined:
    Jun 16, 2015
    Posts:
    1
    Using Unity 2019.4.10 (Ubuntu 18.04, VSCode)

    I had the same problem because I moved the project folder to another directory.
    I realized that in the Assembly-CSharp.csproj, there were some lines, at the end of the file, that were pointing to the previous location of the project. I changed the path to my current path and now everything works fine.

    I guess that what @simonseo suggested, would do exactly that, for my situation.
     
  38. vignesh211

    vignesh211

    Joined:
    Feb 8, 2019
    Posts:
    13
    i don't why a warning symbol occurs near the UnityEngine.UI and before many of those things.What should i do to resolve this.
     

    Attached Files:

  39. Cubemann

    Cubemann

    Joined:
    Oct 22, 2020
    Posts:
    4
    I do not have a reference tab. I am on Mac and I have this problem. I need a solution asap.
     
    Last edited: Feb 20, 2021
  40. Tom-Red

    Tom-Red

    Joined:
    Jun 9, 2013
    Posts:
    15
    Hi, this was four years ago I had this problem so your case might be a little different. Sounds strange that your IDE doesn't have anywhere it shows your DLLs. If your issue was the same as mine, which was specific to the version of Unity I was testing at the time so it might not be relevant.. Try to create a new Unity Project in the latest official version of Unity (Not beta) and see if the issue persists then. If it works, all I did was pull over all my files from the other project and continue working.
     
  41. amzarraif99

    amzarraif99

    Joined:
    Mar 13, 2021
    Posts:
    1

    this works for me...i had some issues because of previous project where i manually install sdk for android build. Then when i wanted to start a new project this problem occur...i follow this step but uncheck everything except the first three
     
    mtjohannes and chuleonski like this.
  42. am_GA

    am_GA

    Joined:
    Oct 4, 2018
    Posts:
    20
    I'm trying to add the UnityEngine.UI reference to my references in VS2019 following (just the VS portion of ) these instructions but it seems like I need to manually search for it in my windows file system. Does anyone know where it's located?

    ------------------

    UPDATE Didn't realize UnityEngine.UI was a package I needed to explicitly download, I downloaded it and now the references are there. Still not recognizing the UnityEngine.UI namespace in my scripts though. Deleting the Library folder did not resolve, neither did checking the "Generate .cs proj files" settings in the External Tools settings menu.
     
    Last edited: Mar 25, 2021
    shahiltp_aramco and mdawntormon9 like this.
  43. Shredimentary

    Shredimentary

    Joined:
    Apr 6, 2021
    Posts:
    1
    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; }
    }
     
  44. usamairshad66666

    usamairshad66666

    Joined:
    Sep 1, 2019
    Posts:
    2
    hey i'm having the same issue. I was removing CloudOnce Leaderboard and was adding google play games services leaderboard. But after removing cloudOnce, it began to show such errors and there's no reference of UnityEngine.UI in visual studio. Tell me what should I do?? :(
    I also tried to do making new project but after closing unity and opening it again, that reacted the same.
     
  45. usamairshad66666

    usamairshad66666

    Joined:
    Sep 1, 2019
    Posts:
    2
    did you resolve it? and how?
     
  46. vignesh211

    vignesh211

    Joined:
    Feb 8, 2019
    Posts:
    13
    Project/Add Reference- Microsoft Visual Studio

    DeSelecting and Selecting again {UnityEngine.UI} resolved the problem for me. JLPT N5-N1 - Microsoft Visual Studio 7_3_2021 12_13_00 PM.png
     
    tomekkie2 likes this.
  47. tomekkie2

    tomekkie2

    Joined:
    Jul 6, 2012
    Posts:
    949
    Thank you for sharing.
    I have tried many fixes, but this one really worked for me.
     
  48. EyeDev44

    EyeDev44

    Joined:
    Apr 8, 2017
    Posts:
    140
    Same on VS code.
     
  49. bionutd

    bionutd

    Joined:
    Dec 22, 2016
    Posts:
    6
    In my case the problem was sold by removing the ExternalDependencyManager folder. The Google.HandlerVersion have conflict with unityui dll.
     
    nasimts likes this.
  50. kingsleyfs

    kingsleyfs

    Joined:
    Jul 5, 2012
    Posts:
    12
    thank you, worked for me, recent install on Mac Pro Unity 2020.3.22f1 VS 8.10.14
     
Thread Status:
Not open for further replies.