DocsShip

Godot runtime

The Godot runtime is an addon written in GDScript, so there’s nothing to compile. The EnvyUI node reads a .envy.json document and builds real Control nodes from it: Panels, Containers, Labels and TextureRects. Focus, gamepad input and theming stay Godot’s own.

Requires Godot 4.6 or newer, the version Envy is tested on.

Install

  1. Copy addons/envy_ui into your project (it’s in every Godot package and AI handoff export) and enable Envy UI in Project › Project Settings › Plugins. A Godot package can also be unzipped into the project root as it is: it adds the addon, your document in ui/ and a demo scene (envy_demo.tscn, run it with F6).
  2. Put your document in the project, for example res://ui/my_ui.envy.json. In Godot 4.6+ it’s imported as an EnvyDocument resource. A .envy project (a zip) loads the same way.
  3. Add an EnvyUI node and set its document, or create it from code.
var ui := EnvyUI.new()
ui.document_path = "res://ui/my_ui.envy.json"
add_child(ui)
ui.ui_event.connect(_on_ui_event)
ui.set_data("player.hp", 40)
ui.goto("HUD")
ui.play("LevelUp")
ui.focus_first_button()

Live reload

While the game runs from the Godot editor, EnvyUI checks the document’s .envy.json file every half second and reloads it when it changes. Save the project from Envy to that file (see Projects and saving), and every change shows up in the running game.

  • The reload keeps the data the game set, the open screen and its overlays. Animations started by game code stop, and autoplay animations start again. document_reloaded fires; screen_changed doesn’t.
  • It works for an imported document and for a document_path read as plain JSON. Projects (.envy) aren’t watched.
  • Exported games never reload. hot_reload = false turns it off in the editor too.
  • check_reload() reloads right away when the file changed.

Properties

Property Meaning
document An EnvyDocument resource
document_path Or a path to a .envy.json file
start_screen Screen to show first, by name or id. Empty shows the first screen that isn’t a component sheet
scale_mode FIT (default) scales the design resolution into the node and stretches to its aspect, like the web runtime. NONE fills the node 1:1
safe_area_margins Safe-area margins in pixels (left, top, right, bottom) for screens set to keep inside the safe area. The default, Vector4(-1, -1, -1, -1), reads them from the display, which Godot reports only on mobile. Set them for TV overscan or a handheld’s system bars
autoplay Play autoplay animations when a screen shows (default true)
use_sample_data Start with the document’s sample data (default true)
hot_reload Reload when the document file changes, while running from the Godot editor (default true)
locale Locale for translated text, like "de", or "pseudo". Empty shows the base text
fonts Family name → Font or a res:// path, for fonts the document doesn’t embed. Use "Family:700" for one weight. An entry here wins over an embedded font of the same family
cancel_closes_overlay ui_cancel closes the top overlay, pressing its focus.cancel button when it has one (default true)
sound_bus The audio bus the document’s sounds play on (default Master)
sounds_muted Silences the sounds Envy plays itself. sound_requested still fires (default false)

Methods

Method Does
goto(screen, transition = {}) Shows a screen by name or id. transition overrides the screen’s own, like {"type": "none"}
push(screen, transition = {}), pop() Opens an overlay, closes the top one
cancel() Closes the top overlay as ui_cancel does: presses its cancel button, else pops. false when no overlay is open
get_stack(), get_screen_names() The open screens (base first), the game’s screens (component sheets left out)
set_data(path, value), merge_data(patch) Changes data. Both emit data_changed
get_data(path = "") A value, or all data with no path
play(anim), stop(anim = ""), is_playing(anim) Animations. stop() with no name stops them all
set_locale(locale), get_locales() Language. set_locale returns the locale it matched ("" for none); get_locales lists the document’s, base first
get_control(name_or_id) The Control built for a layer
focus_first_button() Starts keyboard and gamepad navigation on the initial button, else the first one
is_typing() True while the player types in a text input. Hold your own shortcuts then
play_sound(asset, volume = 1.0) Plays a sound of the document by asset id, at 0 to 1 of its volume. A missing or unreadable one warns once
load_document(path), load_resource(res, path = "") Loads another document
load_project(path) Loads a .envy project
load_document_data(dict) Loads a document from a Dictionary you parsed yourself
reload_document_data(dict) Swaps in a new version of the document and keeps data, screen and overlays, as live reload does
check_reload() Reloads the watched file if it changed. true when it reloaded

goto, push, pop, play and the loaders return true when they worked.

Signals

Signal When
ui_event(event, payload) A button emitted an event
screen_changed(screen_name) A new screen shows: goto, push or pop ran. Not on a reload or a language switch
data_changed(data) Data changed, from set_data, merge_data or a button’s Set data or Toggle data action
document_reloaded The document changed on disk and was reloaded
sound_requested(asset, volume) A sound of the document is due, also while sounds_muted is on, so your game can play it its own way

Sound

Sounds come from the document: the Play sound action and the Hover, Press and Focus sounds of a layer (see Hover, tooltips and sound). Envy only triggers them and your game owns the mix. EnvyUI plays each one on an AudioStreamPlayer on sound_bus, from a pool of six, so a sound that is still ringing isn’t cut off until seven overlap. Set sounds_muted to silence Envy’s own playback. To mix a sound yourself, connect sound_requested: it fires for every sound, muted or not, with the asset id and the volume.

ui.sound_bus = &"UI"
ui.sound_requested.connect(func(asset, volume): print("sound ", asset, " at ", volume))

The sounds are decoded from the bytes in the document, so these formats load:

Format Loads Refused
wav 8-bit and 16-bit PCM, 32-bit float IMA ADPCM, and 24-bit in an extensible header (what ffmpeg writes)
ogg Vorbis Opus
mp3 Yes

A sound that can’t be decoded logs one warning and the UI keeps working. This was checked on Godot 4.7. Godot 4.6 was not run. Re-encode a refused file as 16-bit PCM wav or Vorbis ogg. See also known differences.

Tests

The addon has a headless test suite: godot --headless --path runtimes/godot -s res://tests/run_tests.gd. See known differences for where Godot, Unity and the web draw slightly differently.

Updated View as Markdown