performance_analyzer.gd unless profiling hot paths or optimizing frame rates.
Core Directives
1. Strong Typing
Always use static typing. It improves performance and catches bugs early.
Rule
Prefer
var x: int = 5
over
var x = 5
.
Rule
Always specify return types for functions:
func _ready() -> void:
.
2. Signal Architecture
Connect in
_ready()
Preferably connect signals in code to maintain visibility, rather than just in the editor.
Typed Signals
Define signals with types:
signal item_collected(item: ItemResource)
.
Pattern
"Signal Up, Call Down". Children should never call methods on parents; they should emit signals instead.
3. Node Access
Unique Names
Use
%UniqueNames
for nodes that are critical to the script's logic.
Onready Overrides
Prefer
@onready var sprite = %Sprite2D
over calling
get_node()
in every function.
4. Code Structure
Follow the standard Godot script layout:
extends
class_name
signals
/
enums
/
constants
@export
/
@onready
/
properties
_init()
/
_ready()
/
_process()
Public methods
Private methods (prefixed with
_
)
Common "Architect" Patterns
The "Safe" Dictionary Lookup
Avoid
dict["key"]
if you aren't 100% sure it exists. Use
dict.get("key", default)
.
Scene Unique Nodes
When building complex UI, always toggle "Access as Scene Unique Name" on critical nodes (Labels, Buttons) and access them via
%Name
.
Reference
Official Docs:
tutorials/scripting/gdscript/gdscript_styleguide.rst
Official Docs:
tutorials/best_practices/logic_preferences.rst
Related
Master Skill:
godot-master