"using System;" now created automatically?

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.

C:\Program Files\Unity\Editor\Data\Resources\ScriptTemplates

2 Likes

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.

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.

I’ve been wondering if I could change the default script template for so long. Thanks for that !

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.

1 Like

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.

1 Like

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…”

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?

1 Like