Class SceneManager

Scene management at run-time.

Properties

onClientPresenceChangeEnd: Signal<[clientId: number, sceneName: string, added: boolean]> = ...

Called when a client presence changes within a scene, after the server rebuilds observers.

When this is called, the client has fully loaded the scene.

onClientPresenceChangeStart: Signal<[clientId: number, sceneName: string, added: boolean]> = ...

Called when a client presence changes within a scene, before the server rebuilds observers.

Methods

  • Gets the currently active Scene.

    Returns Scene

    The active scene.

  • Searches through the Scenes loaded for a Scene with the given name.

    The name has to be without the .unity extension. The name can be the last part of the name as displayed in the BuildSettings window in which case the first Scene that matches will be returned. The name can also the be path as displayed in the Build Settings (still without the .unity extension), in which case only the exact match will be returned. This is case insensitive.

    Parameters

    • sceneName: string

    Returns undefined | Scene

    A reference to the Scene, if valid. If not, an invalid Scene is returned. Returns undefined if no scene found.

  • Returns an array of all the game scenes currently open in the hierarchy.

    This does not include any Airship protected scenes.

    Returns Scene[]

    Array of scenes in the hierarchy.

  • Loads a scene only on the local environment. The scene will not have any networking.

    Loading is done additively which means this scene will be stacked on any existing scenes.

    Parameters

    • sceneName: string

      Name of scene to be loaded.

    Returns void

  • Loads a scene for this player. This will also load the scene on server if not already open.

    Must be called from server.

    Parameters

    • player: Player

      The player that will have a scene loaded.

    • sceneName: string

      The name of the scene to be loaded. Do not include ".unity"

    • makeActiveScene: boolean = false

      True to set the newly loaded scene as the active scene.

    Returns void

  • Move a GameObject from its current Scene to a new Scene.

    You can only move root GameObjects from one Scene to another. This means the GameObject to move must not be a child of any other GameObject in its Scene. This only works on GameObjects being moved to a Scene that is already loaded (additive). If you want to load single Scenes, make sure to use DontDestroyOnLoad on the GameObject you would like to move to a new Scene, otherwise Unity deletes it when it loads a new Scene.

    Parameters

    • gameObject: GameObject
    • scene: Scene

    Returns void

  • Sets the scene to be active.

    Parameters

    • scene: Scene

      The scene to be set.

    Returns boolean

    Returns false if the Scene is not loaded yet

  • Unloads a scene only on the local environment.

    Parameters

    • sceneName: string

      Name of scene to be unloaded.

    Returns void

  • Unloads the scene for the player.

    If no players are remaining in the scene, the server will also unload the scene.

    Must be called from server.

    Parameters

    • player: Player

      The player that will have the scene unloaded.

    • sceneName: string

      The name of scene to be unloaded. Do not include ".unity"

    • preferredActiveScene: undefined | string = undefined

      Name of scene to be made the new active scene.

    Returns void