YarnDialoguePresenter
Base class for presenting Yarn dialogue to the player.
class_name YarnDialoguePresenter
extends NodeInherits from Node
Subclass this to create your own dialogue UI. Override run_line to display dialogue lines and run_options to display choices. This class is abstract: attach a subclass such as YarnLinePresenter (
The runner starts every presenter in the same frame and advances only when all of them have returned. Once the token reports next content requested you are promising to finish promptly, but nothing enforces it: the runner just waits (and warns after a few seconds).
run_options follows the same rule, returning the selected option index (>= 0), or -1 if this presenter does not handle options. The first valid selection wins. The token then fires so the rest wind down.
ui/line_presenter.gd) or YarnOptionsPresenter (ui/options_presenter.gd) to your nodes, not this script. Extends Node so presenters can be non-visual (audio, signals, analytics). UI presenters can use _set_presenter_visible to toggle visibility. Presenters: run_line returns when a presenter has finished with the line. Present your content, then await whatever takes time (a typewriter, audio, await token.wait_for_next_content()), clean up, and return. A presenter with nothing to wait for simply returns immediately.The runner starts every presenter in the same frame and advances only when all of them have returned. Once the token reports next content requested you are promising to finish promptly, but nothing enforces it: the runner just waits (and warns after a few seconds).
run_options follows the same rule, returning the selected option index (>= 0), or -1 if this presenter does not handle options. The first valid selection wins. The token then fires so the rest wind down.
#Properties
#dialogue_runner
Reference to the dialogue runner this presenter is registered with. Set automatically when the presenter is added to a runner.
var dialogue_runner: YarnDialogueRunnerType YarnDialogueRunner
#typewriter
var typewriter: YarnTypewriterType YarnTypewriter
#Methods
#on_dialogue_completed()
Called when dialogue ends. Override to clean up your presenter UI.
func on_dialogue_completed() -> void#on_dialogue_started()
Called when dialogue begins. Override to set up your presenter UI.
func on_dialogue_started() -> void#on_node_completed(String)
Called when a node finishes executing.
func on_node_completed(_node_name: String) -> voidParameters
_node_nameString
#on_node_started(String)
Called when a node begins executing.
func on_node_started(_node_name: String) -> voidParameters
_node_nameString
#prepare_for_lines(PackedStringArray)
Called before lines are presented, with IDs of upcoming lines. Override to pre-cache audio, textures, or translations.
func prepare_for_lines(_line_ids: PackedStringArray) -> voidParameters
_line_idsPackedStringArray
#run_line(YarnLine, YarnCancellationToken)
Present a dialogue line to the player. Override this in your subclass to display the line. Access the line's text via
line.text (lazy-computed with substitutions and markup applied) and character name via line.character_name. token can be used to detect when the runner requests hurry-up or skip via YarnCancellationToken.is_hurry_up_requested and YarnCancellationToken.is_next_content_requested, or awaited via YarnCancellationToken.wait_for_next_content. The runner always passes a valid token; the null default exists only so the method can be called manually in tests. Returning ends this presenter's involvement with the line so await anything that takes time before you do typically await token.wait_for_next_content() to hold your content on screen until the line is dismissed. The runner advances only once every presenter has returned. The base implementation returns immediately ("nothing to present"). It must not call YarnDialogueRunner.signal_content_complete: with several presenters attached, a passive one doing so completes every line the instant it appears, cutting off the presenters that actually display it. The runner already advances by itself once all presenters have returnedfunc run_line(_line: YarnLine, _token: YarnCancellationToken = null) -> voidParameters
_lineYarnLine_tokenYarnCancellationToken
#run_options(Array[YarnOption], YarnCancellationToken)
Present dialogue options to the player. Override this in your subclass to display options. Each option's text is available via
option.text (lazy-computed). Return value (same rule as run_line: return when done): - The selected option index (int >= 0), awaiting the player's choice first if needed. - -1 if this presenter does not handle options. When multiple presenters are active all are started concurrently. The first valid selection (>=0 wins; the token then fires so the others wind down — honour it (hide your UI and return -1 when YarnCancellationToken.is_next_content_requested becomes true, e.g. on option timeout)func run_options(_options: Array[YarnOption], _token: YarnCancellationToken = null) -> intParameters
_optionsArray[YarnOption]_tokenYarnCancellationToken
Returns int
Generated from Yarn Spinner for Godot GDScript 3.3.