Coming from Unity's C#? GDScript will feel familiar in many ways—it's dynamically typed, Python-inspired, and designed specifically for game development. This crash course gets you up to speed quickly.
Basic Syntax Differences
# GDScript uses indentation instead of braces
func _ready():
var message = "Hello, Godot!"
print(message)
# Compare to C#:
# void Start() {
# string message = "Hello, Unity!";
# Debug.Log(message);
# }Variables and Types
GDScript supports both dynamic and static typing. You can use type hints for better code clarity and editor support.
# Dynamic typing
var health = 100
var player_name = "Hero"
# Static typing (recommended)
var health: int = 100
var player_name: String = "Hero"
var velocity: Vector2 = Vector2.ZEROLifecycle Methods
Godot's lifecycle methods are prefixed with underscores. Here's the mapping from Unity:
# Unity -> Godot
# Awake() -> _init()
# Start() -> _ready()
# Update() -> _process(delta)
# FixedUpdate() -> _physics_process(delta)
# OnDestroy() -> _exit_tree()Signals (Events)
Godot uses signals instead of C# events. They're built into the engine and incredibly powerful.
# Define a signal
signal health_changed(new_health)
# Emit the signal
func take_damage(amount: int):
health -= amount
health_changed.emit(health)
# Connect to a signal
func _ready():
player.health_changed.connect(_on_health_changed)
func _on_health_changed(new_health: int):
health_bar.value = new_healthNode References
# Get a child node
@onready var sprite = $Sprite2D
# Get a node by path
@onready var health_bar = $UI/HealthBar
# Export for inspector
@export var speed: float = 200.0
@export var jump_force: float = 400.0Next Steps
You now know the GDScript basics! The best way to learn is by building. Try recreating a simple Unity project in Godot—the patterns will quickly become natural.
