SceneBase Class

Common base for all scene types. Holds framework-injected services and lifecycle hooks. Not inheritable outside the engine assembly.

public abstract class SceneBase

Inheritance System.Object → SceneBase

Derived
LoadingScene
Scene

Properties
Audio Audio player for this scene. Available from OnLoadAsync onwards. Not available during OnUnloadAsync(CancellationToken) — use OnExit() for audio cleanup.
Game Game context for this scene. Available from OnLoadAsync onwards. Also available during OnUnloadAsync(CancellationToken); game context does not depend on SDL3-backed services.
Input Input context for this scene. Available from OnLoadAsync onwards. Not available during OnUnloadAsync(CancellationToken) — use OnExit() for input cleanup.
Logger Logger for this scene. Available from OnLoadAsync onwards. Also available during OnUnloadAsync(CancellationToken); logging is thread-safe and does not depend on SDL3-backed services.
Name Gets the display name of this scene. Defaults to the class name. Override to provide a custom name for logging, debug overlays, or save/load systems.
Renderer Renderer for this scene. Available from OnLoadAsync onwards. Not available during OnUnloadAsync(CancellationToken) — use OnExit() for renderer cleanup.
Methods
BeginUnload() Called by SceneManager after OnExit() and before OnUnloadAsync(CancellationToken) to prevent accidental access to SDL3-backed services from background threads. Logger and Game remain accessible after this point.
OnEnter() Called when entering the scene (after loading, before first update). Use this to initialize scene state, start music, or perform any one-time setup. Called on the main thread.
OnExit() Called when exiting the scene (before unloading). Called on the main thread. SDL3-backed services (Renderer, Input, Audio) are still available here — use this for any cleanup that requires them.
OnFixedUpdate(GameTime) Called at a fixed timestep for deterministic simulation logic. Runs zero or more times per frame depending on accumulated time.
OnLoadAsync(CancellationToken, IProgress<float>) Called when the scene is being loaded. Override to load assets. Always pass cancellationToken to async asset-loading calls.
OnRender(GameTime) Called every frame to render visuals, after all ECS systems have rendered via World.Render. Use this for overlays, HUD, or anything that must appear on top of ECS-rendered content.
OnUnloadAsync(CancellationToken) Called during unloading. Override to clean up resources. Always pass cancellationToken to async cleanup calls. Called on a background thread — do not call SDL3-backed services (Renderer, Audio, Input) here. Use OnExit() for any main-thread cleanup that must precede unloading.
OnUpdate(GameTime) Called every frame to update game logic.