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