Auto populated using statements

Since I’ve started using 2022 beta, my scripts have been auto populating themselves with using statements.

Most of the time they just grey out and I never notice, every once in a while it puts some inexplicable statement up there that causes stuff to not work.

A unityeditor using statement prevented me from being able to build a project, it was put in 3 scripts.

some using Unityengine.UI.something caused my UI code to look for it in that something namespace, instead of the usual UI namespace.

I’m using VS2022 on windows11. I know vs2022 did something different with using statements from VS2019.

1 Like

I did notice this odd occurence, there was one time a using statement got added to 3 scripts that were open in VS and it was invalid. I put it down to VS not Unity. Where it got the idea to add an invalid namespace no idea!

Hello, could you have a look at your VS settings? VS2022 is now able to add using directive automatically on paste. You can double check that in “Tools > Options > Text Editor > C# > Advanced”, Using directives tab.

If you are still hitting an issue, please create a support ticket (Help/Send feedback/Report a problem) so we can have a deeper look and track this issue.

Thank you!

5 Likes

Yep, that check box was ticked.

I just changed the IDE to VS2022 when I started using the new unity 2022.beta. I can only add that VS2019 with LTS versions didn’t do it. I say this to not give the impression it started with changing just the unity version.

Thanks for the fast reply.

1 Like

This happens to me also - I make a typo and the autocomplete kinda thing adds the directive to the top without me noticing as part of the autocompleting… backspacing doesn’t remove that extra line, but hitting undo does (VS2022 here as well). Sometimes I only notice because I see the line numbers shift down by 1 line, totally me fumbling keystrokes though… so good tip @sailro , hopefully won’t keep happening now that I’ve unchecked the 3 options that were enabled.

Who thinks of horrible features like this. And then also thinking that enabling these by default is a good idea.

Visual Studio shortcut: Ctrl+R, G
It will remove unused using statements and also order them.

2 Likes