This is an unofficial style guide for Godot - a free, libre and open-source game engine.
-
snake_caseis like_this. -
PascalCaseis LikeThis. -
CONSTANT_CASEis LIKE_THIS.
- Check script_templates for GDScript templates that may help you be more organized at the start. To use them, please refer to this link.
01. @tool
02. class_name
03. extends
04. ## docstring
05. signals
06. enums
07. constants
08. @export variables
09. public variables
10. private variables
11. @onready variables
12. optional built-in virtual _init method
13. optional built-in virtual _enter_tree() method
14. built-in virtual _ready method
15. remaining built-in virtual methods
16. public methods
17. private methods
18. subclasses- Use
PascalCase
class_name MyNode
extends Node- Use
snake_case - Always in past tense
signal button_clicked
signal door_opened- Use parentheses if the signals have parameters
signal points_updated(before, after)- Append
_startedor_finishedif the signal corresponds to the beginning or the end of an action
signal transition_started(animation)
signal transition_finished- Use
PascalCasefor the enum's Name - Use
CONSTANT_CASEfor the enum's KEYS
# Unnamed enum
enum {TILE_BRICK, TILE_FLOOR, TILE_CEILING,}
# Named enum
enum State {
IDLE,
WALK,
RUN,
JUMP,
}- Use
CONSTANT_CASEorPascalCase
const PI := 3.14
const MAX_SPEED := 200# Containing a script resource
const MyScript = preload("res://my_script.gd")- Use
snake_casein most cases
@export var speed := 50.0
@export_range(0.1, 1.0, 0.1) var scale: float- Use
snake_case
var anything
var speed: float
var name := "John"
var another_name: String = "Mike"func do_something(parameter: int) -> void:
return- Use
snake_case - Prepend a single underscore
_name
var _counter: int
var _speed: float
var name := "John"
var another_name: String = "Mike"func _do_something_exclusive(parameter: int) -> void:
return- Use
snake_case
@onready var sword := get_node("Arm/Sword")
@onready var gun := $Arm/Gun
@onready var shield := %Shield - Prepend
is_,can_,has_, etc.
var is_falling := false
var can_double_jump := true
var _has_weapon: bool- Godot's convention:
_on_SignalEmittingNode_signal_name
func _on_Transition_started(which: Animation) -> void:
return- Remove
SignalEmittingNodeif the object connects to itself
class_name HitBox
extends Area2D
func _ready() -> void:
area_entered.connect(_on_area_entered)
return