Up to date
This page is up to date for Godot
If you still find outdated information, please open an issue.
Creating script templates¶
Godot provides a way to use script templates as seen in the
Script Create Dialog while creating a new script:
A set of built-in script templates are provided with the editor, but it is also possible to create new ones and set them by default, both per project and at editor scope.
Templates are linked to a specific node type, so when you create a script you will only see the templates corresponding to that particular node, or one of its parent types. For example, if you are creating a script for a CharacterBody3D, you will only see templates defined for CharacterBody3Ds, Node3Ds or Nodes.
Locating the templates¶
There are two places where templates can be managed.
These are available globally throughout any project. The location of these templates are determined per each OS:
script_templates is detected, Godot will create a default set of
built-in templates automatically, so this logic can be used to reset the default
templates in case you've accidentally overwritten them.
The default path to search for templates is the
res://script_templates/ directory. The path can be changed by configuring
editor/script_templates_search_path setting in the
ProjectSettings, both via code and the editor.
script_templates directory is found within a project, it is simply
Template organization and naming¶
Both editor and project defined templates are organized in the following way:
template_pathis one of the 2 locations discussed in the previous two sections
fileis the custom name you can chose for the template (for example:
extension: will indicate which language the template will apply to (it should be
gdfor GDScript or
Default behaviour and overriding it¶
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 start of 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, and it 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:
The script templates have the same extension as the regular script
files. This may lead to an issue of a script parser treating those templates as
actual scripts within a project. To avoid this, make sure to ignore the
directory containing them by creating an empty
.gdignore file. The directory won't be
visible throughout the project's filesystem anymore, yet the templates can be
modified by an external text editor anytime.
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. See Exclude files from the build in the Microsoft documentation.
It is possible to create editor-level templates that have the same level as a project-specific templates, and also that have the same name as a built-in one, all will be shown on the new script dialog.
To override the default template, create a custom template at editor or project level inside a
Node directory (or a more specific type, if only a subtype wants to be overridden) and start
the file with the
meta-default: true header.
Only one template can be set as default at the same time for the same node type.
Default templates for basic Nodes, for both GDScript and C#, are shown here so you can
use these as the base for creating other templates:
# meta-description: Base template for Node with default Godot cycle methods extends _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