A few days ago, VSCode stop recognizing all Unity Namespaces except UnityEngine. I believe the issue came either when I updated Unity, or Unity’s VSCode package in the package manager. However, I can not roll either of these back, and check if it solves the issue. [Edit: Oops, yes, you can roll them back. And that’s what I did to resolve the issue until the VSCode package is updated.]
This issue ONLY shows up in VSCode. Unity does not report any errors.
Other scripts and namespaces work fine, and assembly definitions are untouched from before the issue began. Also, I noticed that other packages, such as Odin Inspector, are having the same issue.
Some quick things to note, to skip some common solutions:
Everything is up to date, including VSCode, Unity’s VSCode package, and VSCode extensions (Debugger for Unity, C#, etc).
My assembly definitions have the correct dependencies. They were attached and everything worked fine until the issue presented itself.
I have deleted all .csproj and .sln files, while Unity and Hub were off, and had Unity rebuild them. I have also verified that Preferences>External Tools has VSCode as the editor, and tried regenerating project files.
I see the issue in Visual Studio 2022 (preview).
Things I have tried:
Restart/reboot Unity/VSCode/Computer/etc.
Changing the editor in Preferences>External Tools, and Regenerating project files for each option.
Removing and Re-installing Unity’ VSCode package from the package manager.
Moving scripts out of assembly definitions and namespaces.
Thanks for any help!
Unity 2021.1.20f1 Unity Package: Visual Studio Code Editor 1.2.4 VS Code 1.60.1
Try closing Unity, deleting all the csproj files and your Library and obj folders for your project. Then reopen Unity and select Assets → Open C# Project to regenerate all those things.
I don’t know how, but sometimes the project gets out of sync with the library files, which breaks Intellisense.
I saw you mention restarting Unity/VS Code, messing with your preferences, removing the integration package, and moving scripts. I didn’t see you mention actually deleting your csproj files and using “Open C# Project” to regenerate them. It looks like your post was edited shortly before your last response, so maybe you added in more information, I dunno. But in any case, if you’re not actually deleting the files I mentioned first, it’s possible you’re not fully regenerating what you need.
I’ve had this issue pop up numerous times in the past, and doing what I said has always fixed it. If it’s not working for you, I guess your best bet would be to open a bug report?
Okay… I’m sorry if you feel my response was rude, and that I edited my post after you responded… I’m not sure what I’d gain from that. The edit was to add spaces between the bullet lists to make them more readable, and less likely to be skipped or skimmed over. I, too, have had the issue you’re thinking of many times, and yes, deleting those files fixed that problem, but unfortunately, not in this case.
But thank you again for offering your help.
I was hoping someone might know different trick to solve it, or a mistake I might have made somewhere without realizing, that could solve it easily. You might be right; I might need to fill out a bug report. Though with this feeling like a hard to repo bug, I don’t hold a lot of hope for that helping.
Thank you, Kurt, but yes, I also tried these, and to my surprise, they also weren’t the solutions.
HOWEVER, I did manage to finally nail down, and solve, the problem. I doubt this will be the solution to many others who may be dealing with similar issues, but just in case, or to get you thinking about different solutions, I’ll mention it here.
So, as I implied, I was suspecting that Unity’s Package for VSCode was likely behind the issue, but I was thinking I was unable to revert to the previous version because it’s not possible through the Package Manager. Today, though, I remember that you can actually revert Unity Packages manually, by editing two json files Unity uses to keep track of which packages are in the project. I would caution people from quickly jumping in there and playing around of course, and it probably shouldn’t be the first tactic to solve an issue, but if you’re mindful and know which packages you need, it’s fairly simple.
The files are Packages/manifest.json and Packages/packages-lock.json. Just make sure Unity and Unity Hub are closed. After making the changes and restarting Unity, it will load the listed package version. In my case, I changed the VSCode package in both from 1.2.4 => 1.2.3.
VScode now recognizes Unity Namespaces, and Intellisense offers suggestions.
Thank you again to the previous commenters for your help, and good luck to anyone struggling with the issue in the future!
Apparently generating the .csproj separately causes the problem in version 1.2.4 because if you uncheck everything as the image below makes everything work normal. (Remembering to delete previous .csproj)
Oh, interesting. I might give it a try later. Also, I saw Unity updated two versions since I first posted, I wondered if that had an effect with the package.
I have to admit, I don’t know enough about csprojs. Is there a disadvantage to this approach?
Ah, yes, that does indeed seem to be the issue. Thanks for pointing that out, I’ll keep an eye on the issues there to watch for a fix, as it’s still an issue with 2021.1.22f1. You’re previous solution does line up with what they’re reporting in the other issue (which is actually the same issue).
My issue today has been: VS Code suddenly doesn’t recognize classes from the Tilemap Extras package, and wholly doesn’t recognize the InputSystem namespace. Out of no where, when they were working fine before today. I’m supposing I may have updated something, but I can’t remember.
I’ve spent the whole day trying everything I could find, trying old tricks, and this was the last thing I wanted to try but have never had to downgrade a package, so I didn’t know how. The docs are confusing about it. I get that people probably shouldn’t be messing with the manifest files, but jeez… There really ought to be an option in the editor to downgrade packages because of cases like this. Thank you for sharing this!
Issues like this should be easier to find, but at least now I know where to look next time (as it happens too often for me). And thank you for the link!
Ive been having this problem for ages, specifically with UnityEngine.InputSystem and TMPro. Somehow just unchecking everything and clicking the regenerate files button fixed it (without having deleted my previous cproj files). Just posting in case this works for someone else
Just adding that this solution works for anyone struggling to get UnityEngine.Animations.Rigging working. It is the only namespace that didn’t work for me. I struggled for several hours trying various things (deleting .csproj, regenerating project files, reimporting packages, updating VSCode, creating Assembly Definitions, etc).
In the end, I came across this thread, updated my Unity package for Visual Studio Code Editor to version 1.2.5, unchecked everything as per above, and it finally worked.
I used the 1.2.5 as well and my intellisense works perfectly fine but not with methods such as Start(), OnCollisionEnter(), etc. Do you perhaps know why?