Live reload
Save any source file and the running game updates, usually within a few hundred milliseconds, without restarting or losing its state. Live reload is a development feature: shipped games don't have it.
What reloads, and how
| You save | What happens | Typical time |
|---|---|---|
.cast code |
castc emits C, TinyCC builds a new gameplay library, the engine swaps it at a frame boundary and registers behaviors again |
~100-250 ms |
C in native/ |
Rebuilt into the same library (with TinyCC if the game has Cast, else MSVC or gcc/clang) and swapped | ~200 ms |
| A mesh, texture, sound or shader | Re-imported and replaced behind the same handle; everything using it updates, including mesh colliders | 30-250 ms |
.object |
Each existing object of that type takes the new values for fields not changed at runtime (below) | instant |
.level / .chunk |
Placed objects are compared by id: added, removed, moved. Runtime-spawned objects are untouched | instant |
.ui / .style |
The widget tree is rebuilt; focus, scroll and typed text are kept by widget id | ~1 ms |
.screen |
Applied to the active screen without leaving and re-entering it | instant |
What you see in the console:
molten: module reloaded in 210 ms (build 189 ms)
molten: C:/.../objects/coin.object reloaded (3 objects updated)
molten: level 'yard' reloaded: 1 added, 0 removed, 8 kept
molten: UI reloaded in 0.80 ms
molten: screens/playing.screen reloaded
Why state survives
- State and code are separate. All game state is in engine memory: component storage
and arenas. The gameplay module keeps nothing between frames (module-level
letis a compile error), so it can be replaced at any frame boundary. - Handles everywhere. Gameplay refers to objects and assets by handle, so swapping what a handle points at updates every user at once.
- Every component has a schema, so the engine can migrate component data when its layout changes.
Changing a component's fields
When a new module registers a component whose fields changed, every existing instance is migrated by field name:
| Change | Result |
|---|---|
| Field kept | Keeps its value |
| Field added | Gets its default |
| Field removed | Dropped |
| Fields reordered | Values follow their names |
Number type changed (int to float, ...) |
Kept if the new type represents the value exactly; otherwise the new default and one warning per field |
| Incompatible type change | New default, with a warning |
@transient field |
Reset to its default on every reload |
| Default value changed | Existing instances keep their values; only new objects use the new default |
.object files
When you save an object type, each existing object of that type compares each field's current value with its old default (the type's previous value plus any level override):
- equal: the field was not changed at runtime, so it takes the new value;
- different: it was changed (by gameplay or by you in devtools), so it keeps its value.
Values you set in devtools are always kept until you save or discard them.
A consequence: if you change a field's default in the Cast component first, existing objects keep the old value, which no longer equals the "old default", so a later
.objectedit to that field won't reach them either. Restart the level (switch screens) or the game to start fresh.
.level and .chunk files
Placed objects are matched by id:
- a new id is spawned;
- a removed id is destroyed;
- an object whose placement changed in the file gets its whole Transform rewritten, even if gameplay had moved it;
- overrides follow the
.objectrule above.
A placement destroyed by gameplay stays absent until the level loads again. Saving or editing its entry leaves it absent. Physics bodies are reconciled with the remaining placements.
When something is wrong
Nothing breaks the running game. A broken file is reported and the previous version stays:
| Broken | Result |
|---|---|
| Cast code | ERROR: molten: build failed, keeping the running module: followed by file:line:col: error: .... The error is also in the window title and devtools' Console |
| C code | Same: the old module keeps running |
| A module that builds but fails to load | The old module keeps running |
.object with a bad field |
component Coin has no field 'colour' (fields: value, spinSpeed, angle) and kept the previous values of Coin objects |
.ui / .style |
ui/hud.style:14:10: error: invalid CSS declaration 'font-size'; the old tree and styles stay |
| A shader | The old pipeline stays |
| An asset that fails to import | The old data stays |
Fix the file and save again.
What doesn't carry over
- Function values (arrows, named functions stored in variables) belong to the module that created them. Calling one from an older module after a reload stops with an error, so don't store them in long-lived memory.
- Interface values point into the module; keep class references instead.
- Class instances keep their memory, but class layouts are not migrated: changing a
class's fields while instances live in
gamememory is unsafe. Restart the game after changing such a class. - Coroutines don't exist yet, partly because their reload rule is undecided.
Reloading in a team
Several games can connect to one dev server, and file changes reach every running instance. Devtools' live edits are owned by the game: they survive reloads and are lost when the game exits unless you Save to file.