Godot Dialogue System in GDScript (Godot 4)

Опубликовано: 21 Июль 2026
на канале: Generalist Programmer
56
3

Godot dialogue system tutorial: build an NPC dialogue box in GDScript for Godot 4 with a typewriter effect and branching choices.

▶ Full written tutorial (free): https://generalistprogrammer.com/tuto...

Godot dialogue system tutorial — build a clean NPC dialogue box in Godot 4 GDScript, from
scratch. Show lines one at a time, advance on a key press, add a typewriter reveal, and branch
the conversation with player choices. Every line is correct, copy-paste-ready Godot 4 GDScript —
no Godot 3 syntax, no plugin required.

The big idea: keep your writing OUT of your code. This Godot dialogue system stores the
conversation as plain data — an array of line dictionaries, each with a speaker and text — so a
writer can edit lines without ever touching a script. The box just reads the next dictionary.

What we build, step by step:
The dialogue data — an Array of Dictionaries, one per line, with speaker and text. Data-driven
beats hard-coding: no giant if-else tree, and you can load lines from a file or swap languages.
The DialogueBox — a CanvasLayer with a Panel, a name Label, and a RichTextLabel, grabbed with
@onready and unique-name (%) access. It declares a finished signal and hides itself in _ready.
start / show_line / advance — an NPC calls start(lines); show_line paints the current speaker
and text; advancing bumps the index, and on the last line it hides the box and emits finished.
Advancing on input — _unhandled_input with event.is_action_pressed("ui_accept"), plus
get_viewport().set_input_as_handled() so one key press can't double-advance or leak to gameplay.
A typewriter reveal — RichTextLabel.visible_ratio tweened 0 to 1 with create_tween(). Correct
Godot 4 tweening — or skip it and just set the text; the box works either way.
Branching choices — a line carries a choices array; each choice has text and a target index.
We build a Button per choice and connect its pressed signal with .bind(target) to jump branches.

Gotchas that matter: connect signals once (never inside a per-frame loop), consume the input with
set_input_as_handled, and keep the dialogue DATA separate from the UI so writers edit lines and
you never touch the box. That separation is what lets a Godot dialogue system scale from three
lines to three thousand.

Full written companion tutorial with all the copy-paste code:
https://generalistprogrammer.com/tuto...

This dialogue code + 50 more copy-paste snippets — Game Dev Starter Kit ($19):
https://generalistprogrammer.gumroad....

Related Godot tutorials:
Godot save system — https://generalistprogrammer.com/tuto...
More beginner Godot builds — https://generalistprogrammer.com/tuto...

— Chapters —
0:00 Every NPC needs a dialogue box
0:16 Game Dev Starter Kit ($19)
0:38 Dialogue as data (array of lines)
1:37 The DialogueBox (CanvasLayer + nodes)
2:38 start / show_line / advance + input
3:59 Typewriter reveal (visible_ratio)
4:53 Branching player choices (Buttons)
6:04 Gotchas: signals, input, data vs UI
7:01 Recap
7:33 Watch next + subscribe

#gamedev #godotengine #godot