Scene Management

Scenes are the primary unit of content in SafiEngine. Each scene is a JSON-based .scene file containing serialized entities and their components.

File Menu Operations

ActionShortcutDescription
New SceneCtrl+NClear the current scene and start fresh
Open SceneCtrl+OOpen a .scene file from the project's assets/scenes/ directory
Save SceneCtrl+SSave the current scene to its existing path
Save Scene AsCtrl+Shift+SSave the current scene to a new path

On macOS, file dialogs use native osascript panels. On other platforms, scenes default to assets/scenes/default.scene.

Scene Format

Scenes are stored as .scene JSON files in your project's assets/scenes/ directory. The engine serializes and deserializes entities with all their components via Scene::Save() and Scene::Load().

Play Mode

Play mode lets you test your scene with physics, scripts, and audio running live.

Entering Play Mode

When you press Play:

  1. The editor takes a snapshot of the entire scene (serializes all entities to a JSON string)
  2. The engine switches to playing state — physics simulates, native scripts execute, audio plays

Exiting Play Mode

When you press Stop:

  1. The editor restores the scene from the snapshot (deserializes back to the pre-play state)
  2. The selected entity is cleared
  3. The script engine is shut down and re-initialized (hot-reload)
  4. The snapshot is discarded

This means any changes made during play mode (moved objects, spawned entities, etc.) are automatically reverted when you stop.

Unsaved Changes

If you close the editor or open a new scene with unsaved changes, a confirmation dialog appears with three options:

  • Save & Close — Save first, then proceed
  • Discard & Close — Discard changes and proceed
  • Cancel — Stay in the current scene

The editor tracks dirty state via an internal flag that is set whenever the scene is modified.