When enabled the first scene will be loaded when the SceneSwitcher becomes active
When enabled the current scene index will be clamped to the scenes array bounds.
For example when the last scene is loaded and clamp
is true then trying to load the next()
scene will not change the scene.
When clamp
is false and the last scene is loaded then the first scene will be loaded instead.
When enabled will create a button for the Needle menu to switch to the next or previous scene
Reference to the GameObject this component is attached to This is a three.js Object3D with additional GameObject functionality
Unique identifier for this component instance, used for finding and tracking components
Optional
loadingThe scene that is displayed while a scene is loading.
how many scenes can be loaded in parallel
how many scenes after the currently active scene should be preloaded
how many scenes before the currently active scene should be preloaded
the url parameter that is set/used to store the currently loaded scene in, set to "" to disable
The sceneLoaded event is called when a scene/glTF is loaded and added to the scene
Called when a scene starts loading
The scenes that can be loaded by the SceneSwitcher.
Optional
sourceIdentifier for the source asset that created this component. For example, URL to the glTF file this component was loaded from
when enabled the new scene is pushed to the browser navigation history, only works with a valid query parameter set
when enabled you can switch between scenes using keyboard left, right, A and D or number keys
When enabled will automatically apply the skybox from the loaded scene
when enabled will automatically apply the environment scene lights
when enabled the scene name will be used as the query parameter (otherwise the scene index will be used)
Needs queryParameterName
set
when enabled you can switch between scenes using swipe (mobile only)
Checks if this component is currently active (enabled and part of an active GameObject hierarchy) Components that are inactive won't receive lifecycle method calls
True if the component is enabled and all parent GameObjects are active
The index of the currently loaded and active scene
Get the progress of the currently loading scene. This is undefined if no scene is loading
You can also subscribe to the loading event by adding an event listener to the scene switcher.
For example like this sceneSwitcher.addEventListeneer("progress", (e) => {...})
The currently loaded scene. This is undefined if no scene is loaded.
The currently loading scene. This is undefined if no scene is loading.
Checks if this component has been destroyed
True if the component or its GameObject has been destroyed
Controls whether this component is enabled Disabled components don't receive lifecycle callbacks
Gets the forward direction vector (0,0,-1) of this component's GameObject in world space
The layer value of the GameObject this component is attached to Used for visibility and physics filtering
The name of the GameObject this component is attached to Used for debugging and finding objects
Gets the right direction vector (1,0,0) of this component's GameObject in world space
Shorthand accessor for the current scene from the context
The scene this component belongs to
Indicates whether the GameObject is marked as static Static objects typically don't move and can be optimized by the engine
The tag of the GameObject this component is attached to Used for categorizing objects and efficient lookup
Gets the up direction vector (0,1,0) of this component's GameObject in world space
Gets the rotation of this component's GameObject in world space as a quaternion
Note: This is equivalent to calling this.gameObject.worldQuaternion
Sets the rotation of this component's GameObject in world space using a quaternion
The world rotation quaternion to set
Gets the rotation of this component's GameObject in world space as Euler angles (in degrees)
Note: This is equivalent to calling this.gameObject.worldRotation
Sets the rotation of this component's GameObject in world space using Euler angles (in degrees)
The world rotation vector to set (in degrees)
Add a scene to the SceneSwitcher.
If the scene is already added it will be added again.
The url of the scene or an AssetReference to the scene
The AssetReference of the scene that was added
Destroys this component and removes it from its GameObject After destruction, the component will no longer receive lifecycle callbacks
Dispatches an event to all registered listeners
The event object to dispatch
Always returns false (standard implementation of EventTarget)
Optional
earlyCalled at the beginning of each frame before regular updates. Use for logic that needs to run before standard update callbacks.
Optional
lateCalled after all update functions have been called. Use for calculations that depend on other components being updated first.
Optional
onCalled after the scene has been rendered. Use for post-processing or UI updates that should happen after rendering
Optional
onCalled immediately before the scene is rendered.
Current XRFrame if in an XR session, null otherwise
Optional
onCalled before an XR session is requested Use to modify session initialization parameters
The XR session mode being requested
The session initialization parameters that can be modified
Optional
onCalled when this component's collider begins colliding with another collider.
Information about the collision that occurred
Optional
onCalled when this component's collider stops colliding with another collider.
Information about the collision that ended
Optional
onCalled each frame while this component's collider is colliding with another collider
Information about the ongoing collision
Called when the component is destroyed. Use for cleanup operations like removing event listeners
Optional
onCalled when this component joins an XR session or becomes active in a running session
Event data for the XR session
Optional
onCalled when this component exits an XR session or becomes inactive during a session
Event data for the XR session
Optional
onCalled when the context's pause state changes.
Whether the context is currently paused
The previous pause state
Optional
onCalled when a pointer completes a click interaction with this component's GameObject
Data about the pointer event
Optional
onCalled when a pointer button is pressed while over this component's GameObject
Data about the pointer event
Optional
onCalled when a pointer enters this component's GameObject
Data about the pointer event
Optional
onCalled when a pointer exits this component's GameObject
Data about the pointer event
Optional
onCalled when a pointer moves while over this component's GameObject
Data about the pointer event
Optional
onCalled when a pointer button is released while over this component's GameObject
Data about the pointer event
Optional
onCalled when this component's trigger collider is entered by another collider
The collider that entered this trigger
Optional
onCalled when another collider exits this component's trigger collider
The collider that exited this trigger
Optional
onCalled each frame while another collider is inside this component's trigger collider
The collider that is inside this trigger
Optional
onCalled each frame while this component is active in an XR session
Event data for the current XR frame
Optional
onCalled when a field decorated with @validate() is modified.
Optional
prop: stringThe name of the field that was changed
Optional
onXRControllerCalled when an XR controller is connected or when this component becomes active in a session with existing controllers
Event data for the controller that was added
Optional
onXRControllerCalled when an XR controller is disconnected or when this component becomes inactive during a session with controllers
Event data for the controller that was removed
Reload the last scene that was loaded
a promise that resolves to true if the scene was loaded successfully
Optional
resolveCalled when this component needs to remap guids after an instantiate operation.
Mapping from old guids to newly generated guids
Load a scene by its index in the scenes array.
The index of the scene or a string that represents the scene uri (if the url is not known to the SceneSwitcher it will try to load the scene by its uri but it won't be added to the current scenes array. Use addScene to add a scene to the SceneSwitcher)
a promise that resolves to true if the scene was loaded successfully
Load the next scene in the scenes array (this.currentIndex + 1)
If the current scene is the last scene in the array and this.clamp is disabled then the first scene will be loaded.
a promise that resolves to true if the scene was loaded successfully
Load the previous scene in the scenes array (this.currentIndex - 1)
If the current scene is the first scene in the array and this.clamp is disabled then the last scene will be loaded.
a promise that resolves to true if the scene was loaded successfully
Sets the position of this component's GameObject in world space using individual coordinates
X-coordinate in world space
Y-coordinate in world space
Z-coordinate in world space
Sets the rotation of this component's GameObject in world space using quaternion components
X component of the quaternion
Y component of the quaternion
Z component of the quaternion
W component of the quaternion
Sets the rotation of this component's GameObject in world space using individual Euler angles
X-axis rotation
Y-axis rotation
Z-axis rotation
Whether the values are in degrees (true) or radians (false)
Optional
startCalled once at the beginning of the first frame after the component is enabled. Use for initialization that requires other components to be awake.
Starts a coroutine that can yield to wait for events. Coroutines allow for time-based sequencing of operations without blocking. Coroutines are based on generator functions, a JavaScript language feature.
Generator function to start
Event to register the coroutine for (default: FrameEvent.Update)
The generator function that can be used to stop the coroutine
Stops a coroutine that was previously started with startCoroutine
The routine to be stopped
The frame event the routine was registered with
Optional
supportsXRDetermines if this component supports a specific XR mode
The XR session mode to check support for
True if the component supports the specified mode
Switch to a scene by its AssetReference.
If the scene is already loaded it will be unloaded and the new scene will be loaded.
If the scene is already loading it will wait for the scene to be loaded.
If the scene is already loaded and the same scene is requested again it will return the same promise that was returned the first time the scene was requested.
The AssetReference of the scene to switch to
a promise that resolves to true if the scene was loaded successfully
Unload the currently loaded scene.
Optional
updateCalled once per frame during the main update loop. The primary location for frame-based game logic.
The SceneSwitcher can be used to dynamically load and unload extra content
Available scenes are defined in the
scenes
array.Loaded scenes will be added to the SceneSwitcher's GameObject as a child and removed when another scene is loaded by the same SceneSwitcher.
Live Examples
Interfaces
Use the ISceneEventListener interface to listen to scene open and closing events with the ability to modify transitions and stall the scene loading process.
Events
loadscene-start
: Called when a scene starts loadingloadscene-finished
: Called when a scene finished loadingprogress
: Called when a scene is loading and the progress changesscene-opened
: Called when a scene is loaded and added to the SceneSwitcher's GameObjectExample