GDScript

On this page 7

GDScript is the high-level, dynamically typed scripting language built into the Godot engine, designed specifically for writing game logic that works directly with Godot nodes, scenes and signals. Among game engines used in gaming today, it is one of the few languages created for a single engine rather than borrowed from general-purpose programming.

Its syntax resembles Python, with indentation-based blocks, but its semantics follow the engine: every script extends an engine class, receives engine callbacks such as _ready() and _process(delta), and accesses the scene tree without bindings or glue code. The language trades raw execution speed for fast iteration and tight editor integration.

How GDScript runs inside Godot

GDScript source is parsed and compiled to bytecode when a script loads, and a dedicated virtual machine in the engine executes that bytecode. There is no just-in-time compiler, so performance depends on the interpreter and on how much work the script delegates to native engine code.

Each script file defines a class. The first line usually states extends Node2D or another engine type, and an optional class_name registers the script as a global type usable in the editor and in other scripts. When a node carrying the script enters the scene tree, Godot calls lifecycle callbacks in a defined order.

The following table lists the callbacks that structure most gameplay scripts and the moment each one fires.

CallbackWhen it runsTypical use
_init()When the object is constructedSet default values without scene access
_ready()After the node and its children enter the treeCache child nodes, connect signals
_process(delta)Every rendered frameAnimation, input polling, UI updates
_physics_process(delta)Every fixed physics tick, 60 Hz by defaultMovement, collisions, character controllers
_input(event)For each unhandled input eventReacting to keys, touches, gamepad buttons
Core GDScript lifecycle callbacks

The delta argument carries the elapsed time in seconds since the previous call, which keeps motion frame-rate independent. This structure maps the language onto the engine’s game loop without the developer writing the loop itself.

Language features and typing

GDScript is dynamically typed by default but supports optional static typing with annotations such as var speed: float = 200.0 or the inferred form var speed := 200.0. Typed code catches many errors in the editor before the game runs, and in Godot 4 the virtual machine executes typed instructions that avoid some runtime type checks.

Godot 4 rewrote the language implementation and introduced annotations, first-class lambdas and typed arrays. The table below summarizes the features developers use most often.

FeatureExample syntaxPurpose
Export annotation@export var health: int = 100Exposes a property in the Inspector
Onready annotation@onready var sprite = $Sprite2DResolves a node reference when the scene is ready
Signalssignal died and died.emit()Decoupled event notification between nodes
Awaitawait get_tree().create_timer(1.0).timeoutPauses a function until a signal fires
Typed arraysvar enemies: Array[Enemy] = []Restricts elements to one type
Lambdasfunc(x): return x * 2Inline callbacks and sorting rules
Frequently used GDScript features

Memory management uses reference counting for RefCounted objects, such as resources, rather than a tracing garbage collector. Nodes are not reference counted; they are freed explicitly with queue_free(), so forgotten nodes leak until the scene that owns them is released.

GDScript compared with other Godot language options

Godot supports several scripting paths, and GDScript is the default rather than the only choice. C# through .NET offers a mature general-purpose language, while GDExtension lets teams write native code in C++, Rust or other languages that compile against the engine API.

OptionStrengthsTrade-offs
GDScriptBuilt-in editor, hot reload, no external toolchainSlower for heavy computation, engine-only skill
C# (.NET)Static typing, rich libraries, faster numeric codeSeparate SDK, larger exports, limited web export
GDExtension (C++)Native speed, access to low-level engine APIsCompilation step, longer iteration, more complexity
GDExtension (Rust)Memory safety with native performanceCommunity bindings, steeper learning curve
Scripting options in the Godot engine

VisualScript, a node-based alternative, was removed in Godot 4 because few projects used it. Compared with Blueprint Visual Scripting in Unreal Engine or C# in Unity, GDScript sits closer to a text-based scripting layer: lightweight, readable and tied to one engine.

When GDScript is the right choice

GDScript suits gameplay logic, user interfaces, level scripting and prototyping, where most work consists of calling engine functions. In those cases the engine’s native code performs the expensive operations, so interpreter overhead rarely dominates the frame time.

The decision table below matches common project situations with a recommended language path.

SituationRecommended choiceReason
Small team, rapid prototypeGDScriptShortest edit-test cycle
Gameplay and UI scriptsGDScript with static typesReadable code and early error detection
Procedural generation of large worldsC# or GDExtensionTight loops benefit from compiled code
Team with existing C# codebaseC#Reuses skills and libraries
Browser export is a priorityGDScriptMost reliable path for web builds
Choosing a language for a Godot project

Many studios mix languages: GDScript for most scripts and native extensions for performance-critical hot paths such as pathfinding over a large navigation mesh or custom simulation.

Limitations and common mistakes

The main limitation of GDScript is throughput in computation-heavy code. Loops that process thousands of objects per frame can become a measurable bottleneck, and the gap against compiled languages varies widely with the workload and the use of static types.

  • Leaving code untyped hides errors until runtime and forgoes typed-instruction optimizations.
  • Calling get_node() every frame repeats tree lookups; caching references with @onready is cheaper.
  • Putting movement in _process instead of _physics_process causes jitter and inconsistent collisions.
  • Hard-coded node paths break when scenes are reorganized; signals and exported references are more robust.
  • Assuming Python libraries work is a misconception, because GDScript only resembles Python syntactically and cannot import its packages.

A non-technical view

GDScript is the language people use to tell a game made with Godot what to do. The engine already knows how to draw pictures, play sounds and detect collisions. GDScript is how a developer says when and why those things should happen, such as making a door open when the player presses a button.

Think of the engine as a well-equipped theater and GDScript as the script the actors follow. It is written in plain, readable lines, so beginners can learn it quickly, and changes appear in the running game almost immediately.

A concrete example

A two-person independent team builds a 2D platformer in Godot 4. The player character extends CharacterBody2D, with exported properties for run speed of 220 pixels per second and jump height, so the designer tunes them in the Inspector without editing code. Movement lives in _physics_process(delta), which calls move_and_slide(), while a health_changed signal updates the interface.

During testing, a level with 400 collectible coins drops frames because every coin checks the distance to the player each frame. The team switches to Area2D collision signals and adds static types, and the level returns to a stable 60 frames per second while the codebase stays entirely in GDScript.