Your First Page¶
UIFlow pages extend UIFlowPage and are associated with a .tscn scene file.
Create the Page Script¶
# main_menu_page.gd
extends UIFlowPage
class_name MainMenuPage
@onready var start_button: Button = %StartButton
@onready var settings_button: Button = %SettingsButton
func _on_opened(data: Dictionary) -> void:
start_button.pressed.connect(_on_start)
settings_button.pressed.connect(_on_settings)
func _on_closed() -> void:
start_button.pressed.disconnect(_on_start)
settings_button.pressed.disconnect(_on_settings)
func _on_start() -> void:
UIFlow.push(GamePage)
func _on_settings() -> void:
UIFlow.push(SettingsPage)
Create the Scene¶
- Create a
Controlnode namedMainMenuPage. - Attach the script to it.
- Save it as
res://UIScene/MainMenuPage.tscn. - Make sure the root node's
class_namematches the file name:MainMenuPage.
Launch the Page¶
From any entry script:
UIFlow uses UIFlowSceneResolver to automatically find MainMenuPage.tscn and instantiate it.
Lifecycle Hooks¶
A page triggers the following hooks from creation to destruction:
_on_created(data)— instance created, not yet added to the tree._on_opened(data)— added to the tree, before enter animation._on_after_opened()— enter animation finished, focus applied._on_hidden()— covered by a new page._on_shown()— the page above was closed, this page is visible again._on_before_closed()— before exit animation._on_closed()— removed from the stack, after exit animation._on_destroyed()— node about to be freed.
Connecting and disconnecting signals inside _on_opened / _on_closed is a common pattern.