Unity Script Templates in Visual Studio
Objective: Change Visual Studio’s Unity script templates.
When we create a new script in Unity, Visual Studio creates this by default:
Now that’s great for new programmers. But we’ve been doing this long enough that we don’t need a reminder that the Start method is called at the…start. Here’s how we’ll change that.
We’ll have to navigate to the location on our system where Unity keeps its templates. This may take some poking around. We’ll have to do this for the version of Unity we intend to use — each version we’ve installed will have its own templates. Mine were located at (my Unity version is in boldface):
Now open the file named 81-C# Script-NewBehaviourScript.cs.txt. It will look like this:
We can edit this to our preferences. We could get rid of the comments. Or maybe we always find ourselves deleting Start and Update until we need them — go ahead and delete them! We can always use auto-complete to add them on a case-by-case basis. Want to always show the Awake method? Add it!
Here are the changes I made:
And it worked!
NOTE: We may have to modify the permissions of the .txt files to save them. In Windows, right click the file and select Properties. On the Security tab, select Users, click Edit, and check the Full control box. We might need administrator permissions to do this! Once we’re done editing the template, we may want to put the Users permissions back to just Read & execute and Read for future security.