Visual Studio 2022

So, I’ve been using VS2022 with Unity2021.3.16f and it seems while the new Intellisense is nice and convenient (and broken). But my issue is that it adds weird random namespaces in my script. My guess is when I type things, it adds it but does not remove it.

For example it added something like

using UnityEngine.Rendering.FX20.Outlier.Definition (I couldn’t remember exactly, but something like this)

VS says its unnecessary and I have to check all scripts as it fails to build.

Does anyone know how to disable this behavior?

It is difficult to say what kicks off this behavior but many of us have seen it. A quick search of Unity support however would have yielded what we believe to be the solution…

Select “Tools > Options > Text Editor > C# > Advanced” find the Using Directives section and uncheck “Add missing using directives on paste”

C# code will not fail to build if you have using statements referencing libraries you do not use. They display dimmed and it isn’t at all unusual to see this in articles, tutorials and such. That said I tend to remove them.

1 Like

Actually this one does. My guess is because it wasn’t supposed to used for build for example UnityEditor. C# compiles fine, building the project fails.

The massive problem is that it adds random stuff (not the stuff anyone would use) without me ever realizing it. I will try to post one when I come across one.

In the meanwhile, I will try your suggestions. Thanks

You should be using source control so you see what it adds and you can instantly revert.

Most things people consider “massive problems” simply go away when using source control.

Good luck turning this feature off. It is particularly pernicious in Rider, where you can turn it off and it will magically re-enable itself next week. We fought this feature for all of 2018 / 2019 on a large team, constantly breaking our iOS and Android builds because Rider would insist we wanted System.Cryptography or something silly.

Just for completeness:

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:

https://discussions.unity.com/t/778503

Also, try update the VSCode package inside of Unity: Window → Package Manager → Search for Visual Studio Code Editor → Press the Update button

Also, this: https://discussions.unity.com/t/805330/7

I don’t recall seeing any extra using statements since I unchecked the option myself. You really don’t have to post an example, those of us who have seen it have already seen it and I’m fairly certain there is no pattern to discern.