Creating script templates
Godot provides a way to use script templates as seen in theScriptCreateDialog
while creating a new script:

A set of built-in script templates are provided with the editor, but it isalso possible to create new ones and set them by default, both per projectand at editor scope.
Templates are linked to a specific node type, so when you create a scriptyou will only see the templates corresponding to that particular node, orone of its parent types.For example, if you are creating a script for a CharacterBody3D, you willonly see templates defined for CharacterBody3Ds, Node3Ds or Nodes.
Locating the templates
There are two places where templates can be managed.
Editor-defined templates
These are available globally throughout any project. The location of thesetemplates are determined per each OS:
Windows:
%APPDATA%\Godot\script_templates\
Linux:
$HOME/.config/godot/script_templates/
macOS:
$HOME/Library/ApplicationSupport/Godot/script_templates/
If you're getting Godot from somewhere other than the official website, suchas Steam, the folder might be in a different location. You can find it usingthe Godot editor. Go toEditor>OpenEditorData/SettingsFolder
and itwill open a folder in your file browser, inside that folder is thescript_templates
folder.
Project-defined templates
The default path to search for templates is theres://script_templates/
directory. The path can be changed by configuring the project settingEditor > Script > Templates Search Path,both via code and the editor.
If noscript_templates
directory is found within a project, it is simplyignored.
Template organization and naming
Both editor and project defined templates are organized in the following way:
template_path/node_type/file.extension
where:
template_path
is one of the 2 locations discussed in the previous two sections.node_type
is the node it will apply to (for example,Node, orCharacterBody3D),This iscase-sensitive. If a script isn't in the propernode_type
folder, it won't be detected.file
is the custom name you can chose for the template (for example,platformer_movement
orsmooth_camera
).extension
indicates which language the template will apply to (it should begd
for GDScript orcs
for C#).
For example:
template_scripts/Node/smooth_camera.gd
template_scripts/CharacterBody3D/platformer_movement.gd
Default behaviour and overriding it
By default:
the template's name is the same as the file name (minus the extension, prettyfied)
the description is empty
the space indent is set to 4
the template will not be set as the default for the given node
It is possible to customize this behaviour by adding meta headers at the startof your file, like this:
# meta-name: Platformer movement# meta-description: Predefined movement for classical platformers# meta-default: true# meta-space-indent: 4
// meta-name: Platformer movement// meta-description: Predefined movement for classical platformers// meta-default: true// meta-space-indent: 4
In this case, the name will be set to "Platformer movement", with the given custom description, andit will be set as the default template for the node in which directory it has been saved.
This is an example of utilizing custom templates at editor and project level:

Note
The script templates have the same extension as the regular scriptfiles. This may lead to an issue of a script parser treating those templates asactual scripts within a project. To avoid this, make sure to ignore thedirectory containing them by creating an empty.gdignore
file. The directory won't bevisible throughout the project's filesystem anymore, yet the templates can bemodified by an external text editor anytime.
Tip
By default, every C# file inside the project directory is included in the compilation.Script templates must be manually excluded from the C# project to avoid build errors.SeeExclude files from the build in the Microsoft documentation.
It is possible to create editor-level templates that have the same level as a project-specifictemplates, and also that have the same name as a built-in one, all will be shown on the new scriptdialog.
Default template
To override the default template, create a custom template at editor or project level inside aNode
directory (or a more specific type, if only a subtype wants to be overridden) and startthe file with themeta-default:true
header.
Only one template can be set as default at the same time for the same node type.
TheDefault
templates for basic Nodes, for both GDScript and C#, are shown here so you canuse these as the base for creating other templates:
# meta-description: Base template for Node with default Godot cycle methodsextends_BASE_# Called when the node enters the scene tree for the first time.func_ready()->void:pass# Replace with function body.# Called every frame. 'delta' is the elapsed time since the previous frame.func_process(delta:float)->void:pass
// meta-description: Base template for Node with default Godot cycle methodsusing_BINDINGS_NAMESPACE_;usingSystem;publicpartialclass_CLASS_:_BASE_{// Called when the node enters the scene tree for the first time.publicoverridevoid_Ready(){}// Called every frame. 'delta' is the elapsed time since the previous frame.publicoverridevoid_Process(doubledelta){}}
The Godot editor provides a set of useful built-in node-specific templates, such asbasic_movement
for bothCharacterBody2D andCharacterBody3D andplugin
forEditorPlugin.
List of template placeholders
The following describes the complete list of built-in template placeholderswhich are currently implemented.
Base placeholders
Placeholder | Description |
---|---|
| The name of the Godot namespace (used in C# only). |
| The name of the new class. |
| The base type a new script inherits from. |
| Indentation placeholder. The exact type and numberof whitespace characters used for indentation isdetermined by the |
Type placeholders
There used to be, in Godot 3.x, placeholders for GDScript type hints thatwould get replaced whenever a template was used to create a new script, such as:%INT_TYPE%
,%STRING_TYPE%
,%FLOAT_TYPE%
or%VOID_RETURN%
.
The placeholders no longer work for Godot 4.x, but if the settingtext_editor/completion/add_type_hints
fromEditorSettings is disabled, type hintsfor parameters and return types will be automatically removed for a fewbase types:
int
String
Array[String]
float
void
:=
will be transformed into=