Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

"using System;" now created automatically?

Discussion in 'Scripting' started by juicybeast, Sep 22, 2015.

  1. juicybeast

    juicybeast

    Joined:
    Nov 12, 2014
    Posts:
    32
    Since Unity's new update, my visual studio keeps adding "using System;" to my files, but I don't want them, they create conflicts with Object and Random, is there a way to turn that off?

    I could not pinpoint exactly when they were added, they just seem to sometimes pop when I modify a script.
     
  2. hpjohn

    hpjohn

    Joined:
    Aug 14, 2012
    Posts:
    2,190
    C:\Program Files\Unity\Editor\Data\Resources\ScriptTemplates
     
    Ryiah and SnakeTheRipper like this.
  3. Nubz

    Nubz

    Joined:
    Sep 22, 2012
    Posts:
    553
    Exactly this.
    All you need to do is go there and change your script template to have whatever it is you want and don't want when you create a new one.
     
  4. UziMonkey

    UziMonkey

    Joined:
    Nov 7, 2012
    Posts:
    206
    Yes, this is put there by the script templates. However, it just doesn't matter. It might effect compile times by a negligible amount, but nothing to worry about in a typical Unity project. This used to be much different in a language like C++ where header files have to be constantly read and re-read and re-parsed every time. C# is fast though, saying "using System" doesn't incur any more parsing, it just looks at the assembly that's already compiled and grabs a list of classes and methods. There's probably no harm at all in leaving it there.

    However, as others suggested you can remove it from your template file. Or, if you're using Visual Studio 2015 there are tools to clean up using statements available (I think) from the right-click menu.
     
  5. SnakeTheRipper

    SnakeTheRipper

    Joined:
    Dec 31, 2014
    Posts:
    136
    I've been wondering if I could change the default script template for so long. Thanks for that !
     
  6. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    20,148
    The OP stated nothing about performance penalties. Rather this is about the compiler becoming confused between System.Object and Unity.Object. There are a few ways to solve this and one of them is to simply remove the reference.
     
    Kiwasi likes this.
  7. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    Yup the primary reason to get rid of using statements is to reduce namespace collision.

    You can also use them (somewhat) to document and control code dependencies.
     
    Ryiah likes this.
  8. juicybeast

    juicybeast

    Joined:
    Nov 12, 2014
    Posts:
    32
    It has nothing to do with templates, the template does not have "using System", it is not there upon creation either, it is added afterward, consistently, everytime I change the file it gets automatically added. As if it detected Random statements and told itself: "hey he says Random but I don't see any "using System", let's help him..."
     
  9. juicybeast

    juicybeast

    Joined:
    Nov 12, 2014
    Posts:
    32
    Update: It happens when I generate a method through the VS snippets, beginning to think it has something to do with settings in VS and not the update. Anyone know what would the setting be?