๐ŸŽฌ Scene Loading

๐Ÿ“˜ Introduction

The engine allows switching between game scenes dynamically from scripts. This is useful for moving from one level to another, returning to the main menu, or reloading the current scene.

โš™๏ธ Available Functions

Function Description
LoadSceneByName(sceneName) Loads a new scene from the project, completely replacing the current one.

Parameters:
  • sceneName โ€” Name of the scene to load (without extension).
Example:
LoadSceneByName("Level2");
ReloadScene() Restarts the current scene without changing its name. Commonly used to restart levels or retry after a "Game Over".

Example:
ReloadScene();
GetSceneName() Returns the name of the scene currently loaded by the engine.

Returns: string or null

Example:
let scene = GetSceneName();
console.log("Current scene:", scene);

โœ… Basic Example

// "Play" button script
function Start(obj) {
  onClickUp(obj, () => {
    LoadSceneByName("Level1");
  });
}

When clicking the button, the scene Level1 loads and the game continues automatically from its starting point.

๐ŸŽฎ Practical Example: Level Transition

// Player or GameManager script
function OnLevelComplete(obj) {
  console.log("Level completed:", GetSceneName());
  LoadSceneByName("Level2");
}

๐Ÿ” Reloading the Current Scene

// "Retry" button script
function Start(obj) {
  onClickUp(obj, () => {
    console.log("Restarting level...");
    ReloadScene();
  });
}

๐Ÿ’ก Important Notes

๐Ÿงฉ Combined Usage with Other Systems

You can combine scene switching with saving progress, stats, or achievements. For example, save the game before switching:

function OnLevelComplete(obj) {
  SavePlayerData({ level: 1, points: 1200 });
  LoadSceneByName("Level2");
}

This ensures player data is saved right before moving to the next level.