game.scene.load()
Compatibility
Supported languages: C, C++, C#, Python, JavaScript, Lua 5.4, Luau, Java, PHP and HTML/inline JavaScript (binding spellings and return shapes differ).
Use a compatible native engine build and the language tools required by your binding. This does not establish browser/mobile export or release qualification for every OS.
The signature below is the shared reference notation; language examples show the actual binding syntax. Question marks mark optional arguments and explicit defaults are shown where recorded. Do not copy reference notation as a typed declaration.
See Feature status and compatibility for API 1.0/1.1 and per-method restrictions. Engine release tags and Docs v0.1 are independent versions.
Signature
game.scene.load(path)
Setup and usage
Save Menu and Level as distinct scene documents, with Level at scene/level.scene. Put one example inside a generated Start/on_start callback, preferably a Global Startup Script, open Menu, then press Play. Keep the language template imports and callback registration. See Load, unload and switch scenes for exact setup, memory lifetime and errors.
Parameters
| Variable | Type | Required | Description |
|---|---|---|---|
path | relative project path | Yes | A saved scene file in the Play snapshot, such as scene/level.scene. Parent traversal and paths outside the snapshot are rejected. |
Return and timing
Returns the loaded document name as a string. Builds a world without activating it or running scene startup callbacks. Duplicate names/IDs and invalid files raise errors without changing the loaded set.
Execution behavior
Core write timing differs between immediate Lua host calls, deferred JavaScript/Web commands and external SDK query flushes. Scheduled actions advance with the scene clock; synchronous queries evaluate at the call. Follow execution rules and the return/timing notes for this category.
Language examples
Use these snippets inside Start/on_start after generating the Programming Workspace and attaching the script. Python imports rustic, Game and instance from rustic; C++ includes rustic.hpp; C includes rustic.h; C# uses using static Rustic; Java runs inside a Rustic subclass; PHP declares global $rustic, $Game, $instance in its callback. HTML uses an inline script in a ui/ asset. See Lifecycle callbacks for complete registration examples. Public-property examples require a declared integer health property. Scene examples require the named objects to exist before Play.
Lua 5.4
local level = game.scene.load('scene/level.scene')
assert(game.scene.isLoaded(level))
game.scene.switchTo(level)
game.scene.unload('Menu')
print(game.scene.getActive(), #game.scene.getLoaded())JavaScript
const level = game.scene.load('scene/level.scene');
game.scene.switchTo(level);
game.scene.unload('Menu');
print(game.scene.getActive(), game.scene.getLoaded());Python
from rustic import game
level = game.scene.load('scene/level.scene')
game.scene.switchTo(level)
game.scene.unload('Menu')
assert game.scene.isLoaded(level)C++
auto level = game.scene.load("scene/level.scene");
game.scene.switchTo(level);
game.scene.unload("Menu");
if (!game.scene.isLoaded(level)) throw std::runtime_error("Level missing");C#
var level = game.scene.load("scene/level.scene");
game.scene.switchTo(level);
game.scene.unload("Menu");
if (!game.scene.isLoaded(level)) throw new System.Exception("Level missing");Luau
local level = game.scene.load('scene/level.scene')
game.scene.switchTo(level)
game.scene.unload('Menu')
assert(game.scene.isLoaded(level))C
const char *level = Game.scene.load("scene/level.scene");
Game.scene.switchTo(level);
Game.scene.unload("Menu");
if (!Game.scene.isLoaded(level)) r_fail("Level missing");Java
String level = game.scene.load("scene/level.scene");
game.scene.switchTo(level);
game.scene.unload("Menu");
if (!game.scene.isLoaded(level)) throw new RuntimeException("Level missing");PHP
global $game;
$level = $game->scene->load("scene/level.scene");
$game->scene->switchTo($level);
$game->scene->unload("Menu");
if (!$game->scene->isLoaded($level)) throw new Exception("Level missing");HTML / inline JS
const level = game.scene.load('scene/level.scene');
game.scene.switchTo(level);
game.scene.unload('Menu');
if (!game.scene.isLoaded(level)) throw Error('Level missing');Shared Scene lifecycle constraints
- Loading creates a world without selecting it. Scene/object startup scripts run on first activation. Explicitly loaded inactive scenes retain state and do not tick or render. Switching back to those scenes does not rerun Start. switchTo automatically loads missing destinations by name or path, and switching away releases scenes loaded this way. Switching to the same scene preserves it.
- Unloading discards unsaved runtime state, destroys scene/object script instances and releases world, physics, audio and capture state. No unloaded scene cache is retained. Global scripts survive and can load/select a scene when none is active. Shared renderer/asset caches have their own lifetime.
- A missing or ambiguous saved destination, duplicate loads, unknown unloads, invalid or incompatible files and checksum failures raise errors. Failed load/switch operations preserve the selection. Loading never silently recovers a backup. Lifecycle mutations are unavailable during final Play teardown.
- The example requires Menu to be the initially open document name. Save Level before starting Play; scene files are staged from scene/ and scenes/. C uses Game.scene; PHP uses $game->scene. CSS is styling only; HTML uses inline JavaScript.
Errors and debugging
Read the constraints above and the Console diagnostic. Invalid types, non-finite values, stale targets or unavailable native services can fail validation. A failed callback disables the behavior; a failed source reload keeps the last good instance. Exact error messages depend on the language adapter. See Troubleshooting.