Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice

Resolved Auto populated using statements

Discussion in '2022.2 Beta' started by E-Tar, Oct 21, 2022.

  1. E-Tar

    E-Tar

    Joined:
    Jul 3, 2022
    Posts:
    17
    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.
     
    WidmerNoel likes this.
  2. Trindenberg

    Trindenberg

    Joined:
    Dec 3, 2017
    Posts:
    398
    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!
     
  3. sailro

    sailro

    Microsoft

    Joined:
    Jul 30, 2014
    Posts:
    167
    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!
     
  4. E-Tar

    E-Tar

    Joined:
    Jul 3, 2022
    Posts:
    17
    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.
     
    torelsol likes this.
  5. adamgolden

    adamgolden

    Joined:
    Jun 17, 2019
    Posts:
    1,555
    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.
     
  6. WidmerNoel

    WidmerNoel

    Joined:
    Jun 3, 2014
    Posts:
    66
    Who thinks of horrible features like this. And then also thinking that enabling these by default is a good idea.
     
  7. Lo-renzo

    Lo-renzo

    Joined:
    Apr 8, 2018
    Posts:
    1,514
    Visual Studio shortcut: Ctrl+R, G
    It will remove unused using statements and also order them.
     
    adamgolden likes this.