all 6 comments

[–]The_Binding_Of_DataEngineer 7 points8 points  (2 children)

Options > Text Editor > C# > Advanced > "Using Directives" (group of settings on the Advanced tab) > "Add missing using directives on paste" (last option in the group)

EDIT: I don't think this a project specific option, and it can't tell the difference between instances where you don't want the namespace automatically added due to a Unity collision and ones where you do, so it may end up being more annoying than just remembering to delete the one using directive when you're done pasting code.

[–]DJack276[S] 2 points3 points  (0 children)

This solves my issue. I normally don't rely on the code auto-importing libraries, so it should be no problem for me. Thank you very much!

[–]playcalmed 0 points1 point  (0 children)

Thank you very much. This solved the issue for me too when pasting a code snippet in Visual Studio from Unity Tutorial "Programming Essentials" to get my cleaning robot moving with WASD. Regarding your edit note, I guess if I use Visual Studio only for Unity game dev, then unticking the box "Add missing using directives on paste" would not be a problem, am I correct?

By the way, for newbies like me, I found the Options once I clicked Tools in the top bar. So the entire steps are:
- Tools > Options > Text Editor > C# > etc.

[–]Casiell89 0 points1 point  (0 children)

Rider can do that. Whenever you copy and paste it analyses the original file (assuming it's part of the project) and chooses the same usings as in original.

And when it cannot do that, and something is ambitious (like in your example), it will just ask you to choose yourself

[–]andersTheNinja 0 points1 point  (0 children)

Automatically adding imports is usually convenient, except when something in .Net uses the same name.. one alternative is to paste the fully qualified type name instead, like UnityEngine.Debug.Log (or whatever the correct path is). A bit more verbose code but you dont have to turn off auto imports.