Up to date

This page is up to date for Godot 4.2. If you still find outdated information, please open an issue.

스크립트 템플릿 만들기

Godot는 새 스크립트를 생성하는 중에 스크립트 생성 대화 상자에서 볼 수 있는 것처럼 스크립트 템플릿을 사용하는 방법을 제공합니다:

../../_images/script_create_dialog_templates.webp

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.

템플릿 위치시키기

두 장소에서 템플릿을 관리할 수 있습니다.

에디터에서 정의된 템플릿

이 부류의 템플릿은 모든 프로젝트에서 전 세계적으로 사용할 수 있습니다. 템플릿의 위치는 각 OS 별로 결정됩니다:

  • Windows: %APPDATA%\Godot\script_templates\

  • Linux: $HOME/.config/godot/script_templates/

  • macOS: $HOME/Library/Application Support/Godot/script_templates/

만약 script_templates가 감지되지 않으면 Godot에서 기본 내장 템플릿 집합을 자동으로 생성하므로 실수로 경로를 덮어쓴 경우 기본 템플릿을 재설정하는 데 이 로직을 사용할 수 있습니다.

프로젝트에서 정의된 템플릿

템플릿을 검색하는 기본 경로는 res://script_templates/ 디렉토리입니다. 경로는 코드나 에디터를 통해 ProjectSettings에서 editor/script_templates_search_path 경로를 설정하여 변경할 수 있습니다.

프로젝트 안에 script_templates 디렉토리가 없으면 무시됩니다.

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, or CharacterBody3D)

  • file is the custom name you can chose for the template (for example: platformer_movement or smooth_camera)

  • extension: will indicate which language the template will apply to (it should be gd for GDScript or cs 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 start of your file, like this:

# 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:

../../_images/script_create_dialog_custom_templates.webp

참고

스크립트 템플릿은 일반 스크립트 파일과 동일한 확장자를 가집니다. 이로 인해 해당 템플릿을 프로젝트 내에서 실제 스크립트로 취급하는 스크립트 파서에서 문제가 발생할 수 있습니다. 이를 피하려면 빈 .gdignore 파일을 만들어 해당 디렉토리를 무시해야 합니다. 디렉토리는 더 이상 프로젝트의 파일 시스템 전체에서 볼 수 없지만 템플릿은 언제든지 외부 텍스트 에디터에서 수정할 수 있습니다.

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.

기본(Default) 템플릿

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.

The 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

The Godot editor provides a set of useful built-in node-specific templates, such as basic_movement for both CharacterBody2D and CharacterBody3D and plugin for EditorPlugin.

템플릿 플레이스홀더 목록

다음은 현재 구현된 기본 제공 템플릿 플레이스홀더의 전체 목록을 설명합니다.

기본 플레이스홀더

플레이스홀더

설명

_BINDINGS_NAMESPACE_

The name of the Godot namespace (used in C# only).

_CLASS_

새 클래스의 이름(C#에서만 사용).

_BASE_

새 스크립트가 상속받는 기본 타입.

_TS_

Indentation placeholder. The exact type and number of whitespace characters used for indentation is determined by the text_editor/indent/type and text_editor/indent/size settings in the EditorSettings respectively. Can be overridden by the meta-space-indent header on the template.

타입 플레이스홀더

There used to be, in Godot 3.x, placeholders for GDScript type hints that would 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 setting text_editor/completion/add_type_hints from EditorSettings is disabled, type hints for parameters and return types will be automatically removed for a few base types:

  • int

  • String

  • Array[String]

  • float

  • void

  • := will be transformed into =