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. nathanlin

    nathanlin

    Joined:
    Dec 4, 2021
    Posts:
    31
    from Edit - preferences - external tools - choos visual studio open any c# file. then check all generate .csproj file , and click "Regenerate project files" button.
     
  2. Lenvanthis012

    Lenvanthis012

    Joined:
    Aug 24, 2013
    Posts:
    21
    Hello, Everyone,

    After days of torment, and trying all the suggestions listed here, we had still the problem of UnityEngine.UI is not defined.

    How we resolve the problem is the following.

    1) We export the entire project as a unitypackage.
    2) We create the "new" unity project from Unity Hub.
    3) We imported the unitypackage back in.
    4) Build success.

    Peace.
     
  3. Creadous

    Creadous

    Joined:
    May 2, 2019
    Posts:
    1
    Hey I figure out another way around this. I tried a few of your ways mentioned above but nothing worked. When visual studio boots up it says that it loads UnityEngine.UI but I could not find it in "Project/Add Reference- Microsoft Visual Studio". I also regenerated the .csproj files multiple times doesn't change and also swapped / regenerated the Library files just wasted my time. I am using Unity (2020.3.23f1)

    here what I did:

    in visual studio solution it said that the both unityEngine.UI and UnitEditor.UI project weren't full loaded in "( )". Right click and reload them. Now your project can see .UI again. I am guess it fails to load correctly on start up of visual Studio. This is an after screenshot btw.
    Example Of Solution.png
     
  4. atten0007

    atten0007

    Joined:
    Jun 25, 2021
    Posts:
    45
    Hi folks,

    I've the same very S***ty error and I still can't fix it with this article! The error is displayed 4 times in my Unity Editor 2022.1.0b3 on macOS Monterey 12.2. Please note that I've imported the asset ITG from here. I can code with C#, but only a little bit because I hadn't enough time to watch C# tutorials for Unity. Here's the source code of the scripts:

    Script FPSCounter.cs:

    Code (CSharp):
    1. using System;
    2. using UnityEngine;
    3. using Unity.UI;
    4.  
    5. namespace UnityStandardAssets.Utility
    6. {
    7.     [RequireComponent(typeof (UI.Text))]
    8.     public class FPSCounter : MonoBehaviour
    9.     {
    10.         const float fpsMeasurePeriod = 0.5f;
    11.         private int m_FpsAccumulator = 0;
    12.         private float m_FpsNextPeriod = 0;
    13.         private int m_CurrentFps;
    14.         const string display = "{0} FPS";
    15.         private UI.Text m_GuiText;
    16.  
    17.  
    18.         private void Start()
    19.         {
    20.             m_FpsNextPeriod = Time.realtimeSinceStartup + fpsMeasurePeriod;
    21.             m_GuiText = GetComponent<UI.Text>();
    22.         }
    23.  
    24.  
    25.         private void Update()
    26.         {
    27.             // measure average frames per second
    28.             m_FpsAccumulator++;
    29.             if (Time.realtimeSinceStartup > m_FpsNextPeriod)
    30.             {
    31.                 m_CurrentFps = (int) (m_FpsAccumulator/fpsMeasurePeriod);
    32.                 m_FpsAccumulator = 0;
    33.                 m_FpsNextPeriod += fpsMeasurePeriod;
    34.                 m_GuiText.text = string.Format(display, m_CurrentFps);
    35.             }
    36.         }
    37.     }
    38. }
    39.  
    Script ForcedReset.cs:

    Code (CSharp):
    1. using System;
    2. using UnityEngine;
    3. using UnityStandardAssets.CrossPlatformInput;
    4. using Unity.UI;
    5.  
    6. [RequireComponent(typeof (UI.Texture))]
    7. public class ForcedReset : MonoBehaviour
    8. {
    9.     private void Update()
    10.     {
    11.         // if we have forced a reset ...
    12.         if (CrossPlatformInputManager.GetButtonDown("ResetObject"))
    13.         {
    14.             //... reload the scene
    15.             Application.LoadLevelAsync(Application.loadedLevelName);
    16.         }
    17.     }
    18. }
    19.  
    Script SimpleActivatorMenu:

    Code (CSharp):
    1. using System;
    2. using UnityEngine;
    3. using Unity.UI;
    4.  
    5. namespace UnityStandardAssets.Utility
    6. {
    7.     public class SimpleActivatorMenu : MonoBehaviour
    8.     {
    9.         // An incredibly simple menu which, when given references
    10.         // to gameobjects in the scene
    11.         public UI.Text camSwitchButton;
    12.         public GameObject[] objects;
    13.  
    14.  
    15.         private int m_CurrentActiveObject;
    16.  
    17.  
    18.         private void OnEnable()
    19.         {
    20.             // active object starts from first in array
    21.             m_CurrentActiveObject = 0;
    22.             camSwitchButton.text = objects[m_CurrentActiveObject].name;
    23.         }
    24.  
    25.  
    26.         public void NextCamera()
    27.         {
    28.             int nextactiveobject = m_CurrentActiveObject + 1 >= objects.Length ? 0 : m_CurrentActiveObject + 1;
    29.  
    30.             for (int i = 0; i < objects.Length; i++)
    31.             {
    32.                 objects[i].SetActive(i == nextactiveobject);
    33.             }
    34.  
    35.             m_CurrentActiveObject = nextactiveobject;
    36.             camSwitchButton.text = objects[m_CurrentActiveObject].name;
    37.         }
    38.     }
    39. }
    40.  
    If you can tell me, how to fix these very S***ty errors, I'm ging to be very happy because I very urgently need these assets! And sorry for the word S***ty, I wrote it here because all compiler errors in Unity (and this too) are annoying me because any error isn't good! In the attached screenshot there're the lines in the three scripts with the very S***ty compiler errors:
    Bildschirmfoto 2021-12-25 um 18.27.05.png

    Sincerely yours,
    Atten007
     
    viktorcode likes this.
  5. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,713
    Merry Christmas! Please do keep your language professional or else Santa Claus won't bring you presents.

    Remember, it's a computer. It has nothing but 1s and 0s in it, so cursing won't change that.

    Some things to note:

    UnityEngine.UI is now a package:

    https://forum.unity.com/threads/where-did-the-ui-option-in-the-create-menu-go.1134796/#post-7290742

    Annoying possible issue circa October 2021:

    https://forum.unity.com/threads/unityeditor-ui-csproj-not-found.1177432/

    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.

    https://forum.unity.com/threads/intellisense-not-working-with-visual-studio-fix.836599/

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

    Also, this: https://forum.unity.com/threads/no-suggestions-in-vscode.955197/#post-6227874
     
  6. Edson_Rod

    Edson_Rod

    Joined:
    Dec 19, 2021
    Posts:
    1
    This worked here, thank you so much!
     
  7. mtjohannes

    mtjohannes

    Joined:
    Jan 13, 2022
    Posts:
    5
    This worked for me as well. Thanks!
     
  8. karthik888

    karthik888

    Joined:
    Nov 8, 2021
    Posts:
    6
    Hey recently I am facing the same error have you found any solution? I am using the same version of unity
     
  9. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    14,446
    Shredimentary didn't post an error. Please describe your issue and any errors you are seeing related to the UI namespace (the title of this thread).
     
  10. BenCrooks

    BenCrooks

    Joined:
    Jul 30, 2018
    Posts:
    3
  11. steve18624

    steve18624

    Joined:
    Sep 16, 2018
    Posts:
    3
    Deleting the library folder worked for me as well. Like others on this thread, I have a teammate developing on a Linux machine. Maybe this was the cause.
     
  12. jvo3dc

    jvo3dc

    Joined:
    Oct 11, 2013
    Posts:
    1,520
    For me this often happens if I have had multiple instances of Unity open at the same time. The solution is usually very simple, close all Unity instances and open them again.
     
  13. ghanshalamayank

    ghanshalamayank

    Joined:
    Mar 20, 2022
    Posts:
    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>
     
    Last edited: Mar 22, 2022
  14. chestermjr

    chestermjr

    Joined:
    Jan 16, 2018
    Posts:
    2
    For me, I didn't have to do step 2. I only needed to click Regenerate project files after I installed .NET sdk and Mono framework.
     
  15. Behappy859

    Behappy859

    Joined:
    Jul 25, 2019
    Posts:
    15
    This one worked for me. Thankfully i didn't have to delete the library. Uncheck all but the top three yes. thank you
     
  16. Stobros1

    Stobros1

    Joined:
    Jun 15, 2021
    Posts:
    13
    [Unity 2020.3.33f1, Windows]
    I tried some of the fixes like rebuilding the project from both VS'19 and Unity Editor, but it didn't work. Tried deleting the Library folder from my project folder, and the namespace issue is fixed for me.
     
  17. Ranasherry

    Ranasherry

    Joined:
    Aug 8, 2020
    Posts:
    1
    Thankx Bro this worked for me
     
  18. cradiff

    cradiff

    Joined:
    Feb 7, 2015
    Posts:
    65
    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
     
  19. Abdulkadir_Gur

    Abdulkadir_Gur

    Joined:
    Mar 14, 2022
    Posts:
    2




    Hi Bro Solved the problem, very simple. Delete Unity Hub
     
  20. bindon

    bindon

    Joined:
    May 25, 2017
    Posts:
    20
    This is a useful page of solutions to gotchas.
    Perhaps it could be included into the main documentation somehow?
    In my case, deleting the Library folder and then reloading the project (thereby rebuilding it) appeared to fix the problem - that was the first one from the suggestions above that I tried.
    Perhaps some of these other suggestions would also have worked.
     
  21. jvo3dc

    jvo3dc

    Joined:
    Oct 11, 2013
    Posts:
    1,520
    Yes, did anybody try just closing the editor and opening it again? I see everybody deleting folders before doing this. But the thing that fixed things might just be the closing and opening, not the removal of the Library folder or deleting the hub or standing on your head.
     
    Kurt-Dekker likes this.
  22. steril

    steril

    Joined:
    Nov 30, 2014
    Posts:
    8
    I was porting an old project to 2022.3.1f1 and after trying all the provided solutions above with no success, simply installing the Unity UI package from the Unity Registry solved my problem.
     
    HoToFF and Stobros1 like this.
Thread Status:
Not open for further replies.