GDScript & Godot 4 Cheat Sheet
A one-page printable reference for variables, functions, signals, common nodes and the most-used code snippets in Godot 4. Pin it next to your monitor!
A one-page printable reference for variables, functions, signals, common nodes and the most-used code snippets in Godot 4. Pin it next to your monitor!
var health: int = 100 var name: String = "Pip" var speed: float = 4.5 var is_alive: bool = true const MAX_HP = 100 @export var jump_force: float = 12.0
Use @export to edit a variable in the Inspector. const values can't change at runtime.
func _ready(): # runs once when node enters scene print("Hello!") func _process(delta): # runs every frame position.x += speed * delta func take_damage(amount: int) -> void: health -= amount
if health <= 0: queue_free() elif health < 20: print("Low HP!") else: print("OK") for enemy in get_tree().get_nodes_in_group("enemies"): enemy.queue_free() while ammo > 0: ammo -= 1
signal health_changed(new_value) func take_damage(amount): health -= amount health_changed.emit(health) # connect in code: player.health_changed.connect(_on_health_changed) func _on_health_changed(value): hp_label.text = str(value)
Signals let one node tell other nodes when something happens no tight coupling needed.
func _physics_process(delta): var dir = Vector2.ZERO dir.x = Input.get_axis("ui_left", "ui_right") dir.y = Input.get_axis("ui_up", "ui_down") velocity = dir.normalized() * speed move_and_slide() if Input.is_action_just_pressed("jump") and is_on_floor(): velocity.y = JUMP_FORCE
| get_node("Path") | Get a child node by path |
| $NodeName | Shortcut for get_node("NodeName") |
| add_child(node) | Add a node as a child |
| queue_free() | Safely delete a node |
| get_parent() | Reference the parent node |
| preload("res://x") | Load a resource at compile time |
| instantiate() | Create an instance from a PackedScene |
| Node2D | Base 2D node with position/rotation |
| CharacterBody2D | Physics body for players/enemies |
| Area2D | Detects overlaps no collision response |
| Sprite2D | Displays a texture |
| AnimatedSprite2D | Plays sprite animations |
| CollisionShape2D | Shape used for physics/areas |
| Timer | Fires a signal after a delay |
| AudioStreamPlayer | Plays sound effects/music |
_init() โ object created (before scene tree)_ready() โ node + children ready_process(delta) โ every frame (variable rate)_physics_process(delta) โ every physics tick (fixed rate)_input(event) โ raw input events_on_* โ convention for signal callback functions# Change scene get_tree().change_scene_to_file("res://levels/level_2.tscn") # Random number / pick var roll = randi() % 6 + 1 # 1-6 var pick = ["a","b","c"].pick_random() # Wait / delay without freezing await get_tree().create_timer(1.0).timeout # Save / load a value print(JSON.stringify({"score": 10})) # Group nodes & call them all get_tree().call_group("enemies", "take_damage", 5)
Follow one of our free step-by-step Godot 4 workshops in the Workshop hub.
๐ง Browse Workshops โ