- Home /
The type or namespace "UnityEngine" could not be found - Can not edit scripts
Hello, I have a problem, in Visual studio there is an error in the first line "using UnityEngine;", which says: "The type or namespace UnityEngine could not be found. I have no idea what to do, I asked google for hours and did not find a solution. I reinstalled Unity, I reinstalled Visual Studio Community. This error is only occuring in some projects, some other projects work fine. I can temporarily fix the error by clicking "project->Add reference" and then searching "Unity" and ticking everything in the list, but as soon as I open another script or open VisualStudio I have to do it again. Thank you in advance
Answer by villevli · Aug 27, 2016 at 07:32 AM
You can regenerate the Visual Studio project files by deleting the .csproj and .sln files from your Unity project folder. Open any script in your project through the Unity Editor and Unity will recreate the files. You can also use Assets - Open C# Project.
If your issue is not fixed, look in the folder Library\UnityAssemblies in your project directory. The Unity libraries including UnityEngine.dll should be there. If not then you can copy them from another project's folder. You can also try to delete the whole Library folder when the project is not open and let Unity regenerate it. (May take some time depending on your imported assets) (Don't do this if your project is created in Unity 4.2 or earlier. reference)
Thank you for your answer, but it did not fix it. The files are being recreated but the error still occurs.
Are you sure that you actually open the solution and not just a single script file? Without the .csproj file open you will miss all assembly references. Also do you have installed right version with the Visual Studio Tools for Unity? It usually comes with the Unity installer.
The visual studio tool are necessary so you can directly open a file from the editor.
Thanks for your answer. I tried exactly this, but it did not work. I have the right and latest version of VS Tools installed. I have the project opened aswell, not a single file. I just found out, when I delete all .csproj and sln-files the xxx.Assembly.csproj-files are not regenerated,
Look in the folder Library\UnityAssemblies in your project directory. The Unity libraries including UnityEngine.dll should be there. If not then you can copy them from another project's folder. You can also try to delete the whole Library folder when the project is not open and let Unity regenerate it. ($$anonymous$$ay take some time depending on your imported assets) (Don't do this if your project is created in Unity 4.2 or earlier. reference)
It worked! Thank you! I did not have the UnityEngine.dll file, I deleted the Library directory and after 1 $$anonymous$$inute of compilation it's finally working!
Solution: If you don't have UnityEngine.dll in the Library directory of your project just delete the Library directory (while unity is closed). After this open Unity.
Answer by ExNinja · Aug 15, 2019 at 07:01 PM
In Unity 2019.2.0f1, deleting the Library folder does not fix the problem. For me, this problem arose when I tried running the 2019.3.0a11 alpha. Uninstalling and reinstalling Unity 2019.2.0f1 did not help.
However, deleting the Visual Studio Community (macOS) app from the Applications folder and then reinstalling it via Unity Hub did work.
Delete the Visual Studio application from the Applications folder (I have the CleanMyMac app, and it managed the uninstall process for me, but I think that just deleting the app would work too).
In Unity Hub, click the Installs button on the left.
Click the three vertical dots in the top-right corner of any installed version of Unity and choose Add Modules.
Select the Visual Studio module at the top and install it.
That worked for me. :)