Skip to content

Latest commit

 

History

History
176 lines (134 loc) · 3.12 KB

File metadata and controls

176 lines (134 loc) · 3.12 KB

Godot style guide

This is an unofficial style guide for Godot - a free, libre and open-source game engine.

Common naming conventions

  • snake_case is like_this.

  • PascalCase is LikeThis.

  • CONSTANT_CASE is LIKE_THIS.

Code order

  • 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

Class name

  • Use PascalCase
class_name MyNode
extends Node

Signals

  • 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 _started or _finished if the signal corresponds to the beginning or the end of an action
signal transition_started(animation)
signal transition_finished

Enums

  • Use PascalCase for the enum's Name
  • Use CONSTANT_CASE for the enum's KEYS
# Unnamed enum
enum {TILE_BRICK, TILE_FLOOR, TILE_CEILING,}

# Named enum
enum State {
	IDLE,
	WALK,
	RUN,
	JUMP,
}

Constants

  • Use CONSTANT_CASE or PascalCase
const PI := 3.14
const MAX_SPEED := 200
# Containing a script resource
const MyScript = preload("res://my_script.gd")

Exported variables

  • Use snake_case in most cases
@export var speed := 50.0
@export_range(0.1, 1.0, 0.1) var scale: float

Public variables / functions

  • Use snake_case
var anything
var speed: float
var name := "John"
var another_name: String = "Mike"
func do_something(parameter: int) -> void:
	return

Private variables / functions

  • 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

Onready variables

  • Use snake_case
@onready var sword := get_node("Arm/Sword")
@onready var gun := $Arm/Gun
@onready var shield := %Shield 

Other good practices

Booleans

  • Prepend is_, can_, has_, etc.
var is_falling := false
var can_double_jump := true
var _has_weapon: bool

Signal callbacks

  • Godot's convention: _on_SignalEmittingNode_signal_name
func _on_Transition_started(which: Animation) -> void:
	return
  • Remove SignalEmittingNode if the object connects to itself
class_name HitBox
extends Area2D

func _ready() -> void:
	area_entered.connect(_on_area_entered)
	return