You can see in my first if statement there is an extra bracket which should be causing an error but its not. I’m not doing anything special with visual studio or unity its all pretty much a clean install. I save the file, go back to unity, it does its domain reload and no errors pop up. ???
Oh god… so I was missing a bracket and had an extra one where it didn’t belong. So it was an invisible bug. That’s scary… was searching for this for days now and just happened to find it today.
That sounds like your editor / IDE isn’t properly set up with intellisense? It should draw your attention instantly to the issue, and often it fixes it as you’re typing.
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.
Other times it requires you also nuke the userprefs and .vsconfig and other crufty low-value high-hassle files that Visual Studio tends to slowly damage over time, then try the above trick.
Barring all that, move on to other ideas:
Also, try update the package inside of Unity: Window → Package Manager → Search for Visual Studio Editor → Press the Update button
Depending on flavor and version of Visual Studio, it may also have an installation step that you perform within the actual Visual Studio. This step seems finicky at best and may require multiple openings of VS before it comes up.
Update: The VSCode extension has been deprecated and abandoned:
Update: the VSCode integration is back… maybe!?
There may be a community fork available that is receiving updates.
Recently (July 2023) I worked on a Windows11 system that required a Microsoft component to be installed from within Visual Studio before it would work properly with all the OTHER software installed under Unity. I have no documentation on that process as I have only seen it once and it surprised me as well.