Creating a new C# script in Unity fairly simply, just choose the type of class you want, MonoBehaviour
or ScriptableObject
, from the creation menu and give it a name. The file will appear in the project’s assets and upon opening it you’ll see some basic code already in place, generated by Unity. This starter code comes from Unity’s built-in script template, which provides a convenient starting point for most projects.

While the default templates are helpful, they don’t always match specific project or course requirements. In my classes, for example, I require students to include documentation comments in every script, and I emphasize explicit access modifiers, such as marking Start
and Update
as private
. To make this process easier and ensure consistency, we can create our own custom script template that includes all the elements we need from the very first script.
By setting up a custom template, students not only save time but also practice good coding habits and follow the Scripting Style Guide right from the start.
Default Unity Script Templates
A Unity script template is essentially a predefined C# file structure that Unity uses whenever you create a new script. Unity’s default script templates are located in Unity’s installation directory, typically under Editor
> Data
> Resources
> ScriptTemplates
.
Naming Conventions for Script Templates
Each template is a simple plain text (.txt
) file, but the naming of these files is what controls how Unity displays them in the “Create” menu.
The filename of a script template tells Unity where it appears in the creation menu and what it creates. The general format looks like this:
[Order]-[Menu Category]__[Menu Item Name]-[Generated Script Name].cs.txt
- Order number – The number at the start determines the position of the template in the menu. Lower numbers appear first.
- Menu Category – The text after the first hyphen represents the category under which the template appears. This can include spaces. In this case, “Scripting” is the menu category.
- Menu Item Name – After the double underscore
__
, this is the name that shows up in Unity’s “Create → [Category]” menu. - Generated Script Name – After the hyphen, this defines the default name of the new script Unity will generate.
- File Extension – The filename ends with
.cs.txt
. The.cs
is part of the generated script name and tells Unity to create a C# class. The.txt
extension, on the other hand, indicates that the file is a text template that Unity reads when performing the script creation operation.
Submenu For Script Templates
Sub-Submenus
If you want to create additional levels of organization, you can add submenus. Simply extend the naming pattern by adding another submenu name, followed by double underscores. For example, 2-CSG Templates__Advanced Scripts__Scriptable Object
–NewScriptableObject.cs.txt
would create a CSG Templates category, and within that, a submenu called Advanced Scripts, where your ScriptableObject template will be listed.
Default Unity Script Template
The default Monobehaviour script template for Unity 6.2 is named as follows:
1-Scripting__MonoBehaviour Script-NewMonoBehaviourScript.cs.txt
In the editor, it is displayed as follows:
As mentioned above, Unity’s script templates are plain text files that include some initial starter code along with special keywords to dynamically generate scripts that match your project settings and the new script’s name.
Below is an example of Unity’s default MonoBehaviour C# script template:
using System.Collections; using System.Collections.Generic; using UnityEngine; #ROOTNAMESPACEBEGIN# public class #SCRIPTNAME# : MonoBehaviour { // Start is called before the first frame update void Start() { #NOTRIM# } // Update is called once per frame void Update() { #NOTRIM# } } #ROOTNAMESPACEEND#
Script Template – Special Keywords
The default script template includes several keywords that are replaced or managed by Unity during script creation:
#SCRIPTNAME#
: This placeholder is replaced with the name of the new script file. It ensures that the class name within the script matches the file name, which is essential for proper functionality.#NOTRIM#
: This keyword prevents Unity from removing any trailing whitespace in the template. It ensures that formatting and spacing are preserved as specified in the template.#ROOTNAMESPACEBEGIN#
and#ROOTNAMESPACEEND#
: These keywords are used to manage the namespace structure in Unity projects. They mark the beginning and end of the namespace, helping to organize scripts into the correct namespace based on the project’s settings.
Custom Script Templates
While Unity allows custom templates to be saved in the same directory as the default editor templates, modifying files in the Unity installation folder is not recommended. Changes there could affect other projects or be overwritten during Unity updates.
Instead, you can create a ScriptTemplates
folder within your project’s Assets
directory. Unity recognizes this folder as a place for custom templates, so any .txt
file placed here will appear in the Create → [Category] menu, just like the built-in templates. This approach keeps your custom templates project-specific, safe from editor updates, and portable across Unity versions.
To differentiate the Unity folder from the main project folder, a common approach is to add a prefix like “Unity.” For example: GameProjectName-Unity
. This keeps your folder structure clear and avoids confusion between Unity-specific files and the rest of your project resources.
🛠 Create A Custom Unity Script Template
📝 Unity Development | 🕑 15 minutes | Required Files : none
1. Locate or Create the Script Templates Folder:
- In your Unity project, navigate to the
Assets
folder. - Create a new folder named
ScriptTemplates
within theAssets
folder if it doesn’t already exist. This is where we will store our custom script templates.
2. Create a New Template:
- Right-click your
ScriptTemplates
folder in the Project Window, and chooseShow in Explorer
- In Windows Explorer, right-click and choose
New
>Text Document
- Name the file
1-CSG Templates__MonoBehaviour Script-NewMonoBehaviourScript.cs.txt
CSG Templates
In my Computer Simulation & Gaming (CSG) courses, our script templates are saved under the category of CSG Templates for quick reference.
3. Edit the Template:
- Open the newly created template file in a plain text editor, such as Notepad.
- Modify the content of the file to include your custom code below:
/************************************************************ * COPYRIGHT: Year * PROJECT: Name of Project or Assignment * FILE NAME: #SCRIPTNAME#.cs * DESCRIPTION: Short Description of script. * * REVISION HISTORY: * Date [YYYY/MM/DD] | Author | Comments * ------------------------------------------------------------ * 2000/01/01 | Your Name | Created class * * ************************************************************/ using UnityEngine; #ROOTNAMESPACEBEGIN# public class #SCRIPTNAME# : MonoBehaviour { // Awake is called once on initialization private void Awake() { #NOTRIM# }//end Awake() // Start is called once before the first Update private void Start() { #NOTRIM# }//end Start() // Update is called once per frame private void Update() { #NOTRIM# }//end Update() /// <summary> /// A custom method example. /// </summary> /// <param name="exampleParameter"> A parameter that demonstrates passing data to the method. ///</param> private void CustomMethod(int exampleParameter) { #NOTRIM# }//end CustomMethod(int) }//end #SCRIPTNAME# #ROOTNAMESPACEEND#
Script Template Updates
New or modified script templates won’t take effect until the Unity Editor is reloaded. Close and reopen the editor to apply them.
4. Create Script from Template
- Exit and reopen the Unity Editor
- In the Project Window, right-click and choose
Create
>CSG Templates
>Monobehaviour
- Give a relevant name to the script. See class naming conventions.

Scripts Folder
When creating new scripts, make sure they are placed in the correct Assets folder. According to the Asset Naming File Structure, all scripts should be stored in a Scripts folder within the Assets directory. Be sure the Scripts folder exists and is selected in the Project window before creating a new script.
5. Previewing a Script
- Select the newly generated script from the Project Window.
- In the Inspector Window, you can view a preview of the file. Notice that the documentation comments are included as defined by our template.

- Double-click the script to open your IDE and start developing.
External Script Editor
A standard Unity installation includes Visual Studio Community, which is set as the default IDE for opening scripts. To use a different IDE, go to Edit
> Preferences
> External Tools
and select the External Script Editor from the list of installed options.
That is all there is to creating a custom script template in Unity! Remember that new or modified templates won’t take effect until the Unity Editor is reloaded, so be sure to close and reopen it before testing.
From here, you can:
- Add additional templates for different script types (ScriptableObjects, interfaces, managers, etc.).
- Customize headers with comments, namespaces, or licensing info.
- Standardize templates across your team to keep code consistent.
This makes script creation faster, cleaner, and aligned with your project’s workflow.