Skip to main content

AltaSceneManager

A static class in Root.Township, the global namespace.

Static helper that loads and unloads the registration, main menu, game and loading scenes, with a loading screen shown in between. Mostly client flow, but the server also uses LoadGameScene and ReturnToMainMenuAsync when hosting.

Fields​

13 private and internal fields
MemberWhat it is
private static Scene gameSceneThe loaded game scene.
private static AsyncOperation gameSceneLoadOpThe running background load of the game scene, or null.
private static bool isGameSceneActivatedTrue once the game scene has been made the active scene.
private static bool isGameSceneFullLoadedFlag for a fully loaded game scene. Reset on unload; checked by LoadGameScene to skip loading.
private static bool isOnlineFalse after LoadNoInternetScene, which stops any further scene changes.
private const int LoadingDelayDelay in milliseconds used between polls of scene load and unload operations.
private static AsyncOperationHandle<GameObject> loadingObjectAddressableHandleAddressables handle for the loading screen prefab.
private static Scene loadingSceneThe temporary loading scene, if one exists.
private const string LoadingSceneNameName of the temporary loading scene, "Loading Scene".
private static TaskCompletionSource<bool> loadingSceneTcsCompleted when the loading screen is removed. LoadNoInternetScene waits on it.
private static readonly Logger loggerNLog logger for this class.
private static Scene menuSceneThe main menu scene.
private static Scene registrationSceneBacking field for RegistrationScene.

Properties​

MemberWhat it is
static bool IsLoading { get; private set; }True while a scene change is in progress. Blocks other scene changes.
static float LoadProgress { get; private set; }Progress (0 to 1) of the scene load currently running, for the loading screen.
2 private and internal properties
MemberWhat it is
private static bool CanChangeScene { get; }True when no load is running and the game hasn't switched to the no-internet scene. Every public load checks this first.
private static Scene RegistrationScene { get; }The registration scene named in MenuSettings, looked up and cached on first use.

Methods​

MemberWhat it is
static async Task CreateLoadingScene()Creates the empty "Loading Scene", makes it active and spawns the loading screen object in it. Reuses the scene if it already exists.
static async Task LoadGameScene(int sceneIndex)Unloads the main menu and loads the game scene at the given index in MenuSettings.GameScenes, then sets it active and finds its NetworkScene. Called by GameMode.
static async Task LoadMainMenuSceneAsync()Shows the loading screen, unloads the registration scene and loads the main menu scene.
static async void LoadNoInternetScene()Fades out, unloads the registration, menu and game scenes and loads "No Internet Scene". Blocks further scene changes.
static async Task LoadRegistrationSceneAsync()Unloads the main menu and loads the registration (login) scene, or just activates it if it's already loaded.
static async Task<bool> LoadTutorialAsync()Shows the loading screen, unloads the registration scene and joins the tutorial through ApplicationStartupManager.JoinTutorialAsync. Returns false if that fails.
static async Task ReturnToMainMenuAsync()Resets game scene state, shows the loading screen, unloads the game scene and loads the main menu.
static async Task UnloadGameSceneAsync()Unloads the game scene and resets the game scene flags. Logs an error if it isn't loaded.
21 private and internal methods
MemberWhat it is
private static void CleanUpLoadingScene(Scene targetScene)Moves the loading scene's non-temporary objects into the target scene, then removes the loading screen.
private static async Task CreateLoadingSceneCamera()Spawns the loading screen prefab from Addressables into the loading scene. Does nothing on a headless server.
private static async void DelayReleaseLoadingObject()Android only: releases the loading screen's Addressables handle one frame after the loading scene unloads.
private static void DestroyTempSceneObjects()Destroys root objects in the active scene that have a TempSceneObject component.
private static async Task FinishLoadingGameSceneInBackground(string gameSceneName)Waits for the background game scene load to reach 90%, allows activation, waits for it to finish and warms its shaders.
private static void FlagLoadingStarted(string loadOperationName)Sets IsLoading to true and logs which operation started.
private static void FlagLoadingStopped(string loadOperationName)Sets IsLoading to false and logs which operation stopped.
private static async Task LoadMainMenuSceneInternalAsync()Loads the menu scene additively (or just activates it if already loaded), updating LoadProgress, then warms its shaders.
private static async Task LoadSceneAsync(string sceneName, LoadSceneMode mode)Loads a scene by name in the given mode and updates LoadProgress until it's done.
private static void MoveObjectsToTargetScene(Scene sourceScene, Scene targetScene, bool isForcingAllObjects)Moves root objects from one scene to another, skipping TempSceneObject ones unless forced.
private static void OnLocalPlayerSet(PlayerController player)Hooked to PlayerController.LocalPlayerSet during a game load. Removes the loading screen once the local player exists.
private static void RemoveLoadingScreen()Unloads the loading scene, destroys temporary objects, clears IsLoading and completes the loading task.
private static void StartLoadingGameSceneInBackground(string sceneName)Starts an additive load of the game scene with activation held back until FinishLoadingGameSceneInBackground.
private static void SwitchFromMenuToGameScene()Makes the game scene active and sets NetworkSceneManager.Current to the NetworkScene found on its root objects.
private static bool TryGetLoadingScene(out Scene scene)Finds the loading scene, from the cached value or by name.
private static bool TryGetMenuScene(out Scene scene)Finds the main menu scene, from the cached value or by the name in MenuSettings.
private static async Task UnloadInitialActiveSceneInEditor(Scene originalActiveScene)Editor only: unloads a game scene that was open in the editor before play started.
private static void UnloadLoadingScene()Starts unloading the loading scene and clears the cached handle.
private static async Task UnloadMainMenuScene()Tells VrMainMenu to prepare, then unloads the main menu scene if it's loaded.
private static async Task UnloadRegistrationSceneAsync()Unloads the registration scene if it's loaded.
private static async Task WarmUpSceneShaders(Scene scene)Runs Warm on every ShaderVariantWarmer found on the scene's root objects.