Add additional script templates?

I know that it’s possible to modify the default script templates created from the Create->C# Script editor menu item, but I’d like to have additional script templates so that I could, for example, create a new menu item called “Create->C# Interface” or “Create->C# EventArgs”. Is there a way to do this?

I know of roundabout, sub-optimal ways to accomplish similar things but without the full functionality of creating the file and having it added to the project with proper naming, etc.

I’ve experimented with this recently, and it does appear that you can do this!

In the folder where your ScriptTemplates are stored (Unity/Editor/Data/Resources/ScriptTemplates in case anyone is wondering), just make a duplicate of whichever type of file you’d like to create. For instance, for C# files make a duplicate of the 81-C# Script-NewBehaviourScript.cs file.

Now, change the 81 to the next value larger than the last file in the templates folder (probably 85). Change the “C# Script” text to whatever you want your template to show up as in the Create menu in Unity.

You can probably change the “NewBehaviourScript” text to another name (whatever you want the default name of your file to be called), though I can’t confirm this, as I’ve left all my templates with the default NewBehaviourScript text.

Open up the file and edit it to your liking.

And finally, if you had Unity open while doing this, save your work and restart it.

One Warning:

I haven’t noticed any issues with this method, but the face that the first template starts at 80 suggest that there are other files which use this numbering format. Whether there are files beyond 84 that exist, and whether new template files will conflict with these files is something we’ll just have to find out the hard way.

I’m hopeful that the good people at Unity wouldn’t allow us to break the program by simply adding a file to a folder, but there are no guarantees!

If someone could chime in on this, that would be great!

right folks, I’ve just messed about with unity templates until they’re the way I like them. the filename is king.

inside the ScriptTemplates folder, you can have many templates, but how you name them affects how(if) they’ll show up in the context menu.

the format is:

{integer index}-{context menu first level name}[(optionally)__{context menu second level name}]-{default file name}.txt


82-C# Script__MonoBehaviour-NewBehaviourScript.cs.txt

^    ^         ^                   ^

IDX LVL1    LVL2                NAME

Hope that’s clear enough

(format of this post will probably break, sorry)

I’d like to chip in with a clarification (sry for yet another necro).

The format is:


{SortingIndex} is some number used to order the items in the “Create New” context menu, duplicates are allowed.

{MenuItemName} is a string that defines the name of the item. It can be a nested item, use double underscores “__” to indicate going into a folder, sorta like with the [CreateAssetMenu] attribute, except in that one they use forward slash “/” instead. A bit confusing.

{FileName} is the default suggested filename that Unity has highlighted, when the user clicks the menu item to create the file. As @djfunkey mentioned, there seems to be some additional magic string searches going on for the filename. If the string “Test” appears in the filename (case insensitive), Unity will automatically create and move the new file to an Editor folder, in the current directory.

Path to ScriptTemplates folder (thanks to @Eliot_L):

C:\Program Files\Unity\Editor\Data\Resources\ScriptTemplates (Windows)

/Applications/ (Mac)

/opt/Unity/Editor/Data/Resources/ScriptTemplates (Linux)

Example custom script template filenames:

81-UI Widget C# Script-NewUIWidget.cs.txt

82-C# Editor Script-NewBehaviorEditorTest.cs.txt

Thanks for the info, @gilley033! I made a gist with some examples of this for C# plain classes, interfaces, and unit tests:

The format appears to have updated in Unity 5.3.5.

91-Name In Asset Menu-DefaultNameOfNewScript.FileExtension.txt

for example: 91-Util Script-NewUtilScript.cs.txt

Sorry to necro a old thread, but a heads up if you want to create any custom editor template scripts, as in ‘public void #SCRIPTNAME# : EditorWindow {’ (any script to edit the editor).
The current default one that Unity provides automatically creates an Editor folder in the directory you call to create the script.

The format is:

{integer index}-{context menu first level}[(optionally)]__{context menu second level name}]-{any thing with the word ‘test’ in it}.txt


74-Editor Scripts__EditorWindow-EditorWindowTest.cs.txt

75-Editor Scripts__EditorEditor-testEditor.cs.txt

76-Editor Scripts__Attribute-EditorTestAtribute.cs.txt

The actual word ‘Test’ can be upper or lowercase.

Another approach can be: