Hi all,
I’m having an issue with Visual Studio Code.
ALL of my scripts are suddenly saying: UnityEngine: Unnecessary using directive.
Then, all of my scripts are littered with errors, due to everything related to Unity saying The type or namespace X cannot be found. Such as MonoBehaviour, GameObject, Camera, etc.
However, all of the scripts compile and there are no actual errors when running the project. So, this seems to be some disconnect between VS Code and Unity. It seems to strictly be on VS Code’s side. The issue is, I didn’t change anything. It just suddenly happened a few days ago, and I haven’t been able to get rid of it. I’ve shut everything down, restarted, tried other projects, etc. and it’s all the same. A sea of red “errors” in VS Code.
Unity Hub, Unity, and VS Code are all up to date, as well as all of the associated Unity plugins and VS Code extensions.
It seems like I got it to work by 1. deleting the library 2. deleting csproj files in the root project folder 2. opening unity and adding variables using the previously problematic namespaces 3. restarting unity and vs. I don’t know if all these steps were necessary or what the heck is happening but that’s what I did.
I can confirm that this solved it for me. Just create a new script in Unity, open it up by double clicking in the Project, problem fixed in Visual Studio. I originally opened the script in Unity from the Inspector (instead of the Project), and I also upgraded to a new version of Unity, so those may be factors to why this happened.