githubEdit

Switch Between Scenes

Dynamically load and switch between multiple 3D scenes with the SceneSwitcher component. Perfect for galleries, portfolios, and multi-scene experiences. Works in Unity and Blender.

Dynamically load and switch between fully interactive glTF content - complete scenes or individual assets - with smooth transitions and preloading.

:::tip Works with Unity and Blender The SceneSwitcher component is available for both Unity and Blender integrations. :::

:::tip Needle Engine's Superpower: Interactive glTF/glb Files A key feature of Needle Engine is that glTF/glb files are fully interactive. When you export from Unity or Blender, your scenes include not just 3D models, but all components, scripts, physics, animations, and custom logic. SceneSwitcher loads these complete, self-contained interactive experiences - not just static geometry! :::

What You Can Do

  • Load Fully Interactive Scenes - Each scene is a complete Unity/Blender export with all its components, scripts, physics, animations, and interactivity

  • Self-Contained Experiences - Loaded scenes bring their own logic (DragControls, particle systems, custom scripts, etc.)

  • Multiple Scenes - Switch between different 3D environments

  • Multiple SceneSwitchers - Have several independent SceneSwitchers in one scene, each managing different content

  • Keyboard Navigation - Use arrow keys, A/D, or number keys to switch scenes

  • Swipe on Mobile - Swipe left/right to navigate between scenes

  • Preloading - Automatically preload nearby scenes for instant switching

  • Loading Scenes - Optional loading screen while switching

  • Browser History - Back/forward buttons work with scene changes

  • Custom Transitions - Control scene open/close behavior with code

Perfect for:

  • Portfolio and gallery websites

  • Product showcases with multiple variations

  • Multi-level experiences

  • Interactive storytelling

  • Virtual museums and exhibitions

Quick Start

Basic Setup

In Unity or Blender:

  1. Create an empty GameObject

  2. Add the SceneSwitcher component

  3. Add your scene files to the Scenes array

  4. Export and view - first scene loads automatically!

Controls:

  • Arrow Keys or A/D - Switch scenes

  • Number Keys (1, 2, 3...) - Jump to specific scene

  • Swipe (mobile) - Swipe left/right to navigate

Three Different Scenes

The video above shows three distinct scenes:

  1. Cylinder Garden (Scene 1) - Decorative plants on cylinders

  2. Gold & Fog (Scene 2) - Golden spheres in misty atmosphere

  3. Lightmapping (Scene 3) - Statue with colored lighting

Users can navigate between them seamlessly using Previous/Next buttons or keyboard controls.

Scene Organization Patterns

SceneSwitcher is incredibly flexible - you can organize your scenes in different ways depending on your needs:

Pattern 1: Replace Entire Scene Content

For completely different environments (like the video above), use a minimal root scene:

Root Scene (main.glb):

  • Camera

  • Lights (optional - scenes can provide their own)

  • SceneSwitcher component

  • UI elements (optional - Previous/Next buttons)

Individual Scenes:

  • scene1.glb - Complete environment with all objects

  • scene2.glb - Complete environment with all objects

  • scene3.glb - Complete environment with all objects

This pattern is perfect for:

  • Portfolio galleries where each scene is completely different

  • Virtual museums with distinct exhibition rooms

  • Product showcases with entirely different setups

See it in action:

Pattern 2: Replace Parts of the Scene

For partial content switching, keep persistent elements in the root scene and load interactive files:

Root Scene:

  • Camera with OrbitControls

  • Lighting setup (stays consistent)

  • Ground plane or environment

  • UI and navigation

  • SceneSwitcher component

Individual Scenes (exported from Unity or Blender):

  • Each scene is a full glTF export with all its components

  • Loaded scenes bring their own scripts (DragControls, particle systems, etc.)

  • Scenes can have animations, physics, UI, and custom logic

  • Completely self-contained interactive experiences

This pattern is perfect for:

  • Product configurators where environment stays the same

  • Loading interactive demos or mini-games

  • Character customization with persistent background

  • Swapping focal content while keeping context

  • Portfolio of interactive 3D experiences

See it in action:

Pattern 3: Multiple SceneSwitchers (Very Powerful!)

You can have multiple SceneSwitcher components in the same scene, each managing different parts:

Example: Showroom with Multiple Products

Each SceneSwitcher:

  • Operates independently

  • Has its own scene array

  • Can use different navigation (one via UI, another via keyboard)

  • Loads/unloads only its own content

This pattern is perfect for:

  • Showrooms with multiple independent product displays

  • Comparison tools (left side vs right side)

  • Multi-panel presentations

  • Complex configurators with multiple customization areas

Example Code for Multiple Switchers:

:::tip Multiple SceneSwitchers Power Having multiple SceneSwitchers is what makes Needle Engine's scene management incredibly powerful and flexible. You're not limited to switching entire environments - you can switch specific parts independently! :::

Settings

Basic Settings

Setting
What it does
Default

Scenes

Array of scene files to switch between

[]

Auto Load First Scene

Load first scene automatically on start

true

Loading Scene

Optional scene to display while loading

undefined

Setting
What it does
Default

Use Keyboard

Enable keyboard shortcuts (arrows, A/D, numbers)

true

Use Swipe

Enable swipe navigation on mobile

true

Clamp

Stop at first/last scene (or loop around)

true

URL & History

Setting
What it does
Default

Query Parameter Name

URL parameter for current scene (e.g., ?scene=1)

"scene"

Use Scene Name

Use scene name in URL instead of index

true

Use History

Add scene changes to browser history

true

Scene Settings

Setting
What it does
Default

Use Scene Lighting

Apply lighting from loaded scene

true

Use Scene Background

Apply skybox from loaded scene

true

Preloading

Setting
What it does
Default

Preload Next

How many scenes ahead to preload

1

Preload Previous

How many scenes behind to preload

1

Preload Concurrent

Max concurrent downloads

2

UI

Setting
What it does
Default

Create Menu Buttons

Add Previous/Next to Needle menu

false

Examples

Create a 3-scene portfolio:

In Editor:

  1. Add SceneSwitcher component

  2. Add 3 scenes to the Scenes array:

    • Scene1.glb

    • Scene2.glb

    • Scene3.glb

  3. Enable Clamp to stop at first/last scene

  4. Users navigate with arrows or swipe

Let users loop through scenes endlessly:

In Editor:

  1. Add scenes to SceneSwitcher

  2. Disable Clamp

  3. After the last scene, pressing "next" returns to first scene

  4. Great for continuous presentations

Product Configurator

Show different product variations:

Custom Loading Screen

Show a loading scene while switching:

In Editor:

  1. Create a simple loading scene (e.g., spinner, progress bar)

  2. Export it as loading.glb

  3. Assign it to Loading Scene on SceneSwitcher

  4. The loading scene appears during transitions

Scripting

Switch Scenes Programmatically

Add Scenes Dynamically

Listen to Scene Events

Check Loading State

Preload Scenes

Reload Current Scene

Unload Scene

Advanced Features

ISceneEventListener Interface

Add custom logic when scenes open or close:

URL Parameters

SceneSwitcher syncs with URL parameters automatically:

Users can:

  • Bookmark specific scenes

  • Share direct links to scenes

  • Use browser back/forward to navigate scenes

Keyboard Shortcuts

Default keyboard controls:

  • Arrow Right / D - Next scene

  • Arrow Left / A - Previous scene

  • Number keys (1-9) - Jump to scene by index (1 = first scene)

Disable with useKeyboard = false.

Mobile Swipe

Swipe left/right to navigate on touch devices.

Configure threshold or disable with useSwipe = false.

Common Questions

How many scenes can I add? No hard limit, but be mindful of total file size. Use preloading settings to control memory usage.

Can scenes have different lighting? Yes! Enable Use Scene Lighting and Use Scene Background to apply each scene's lighting/skybox.

How do I prevent users from jumping scenes? Set useKeyboard = false and useSwipe = false, then only provide your own UI for navigation.

Can I load scenes from external URLs? Yes! Use addScene("https://example.com/scene.glb") to add external scenes.

What's the difference between Loading Scene and regular scenes? The loading scene appears while other scenes load. It's optional but improves UX for large scenes.

How does preloading work? SceneSwitcher automatically downloads nearby scenes based on Preload Next and Preload Previous settings. This makes transitions instant.

Can I use this with multiplayer? Yes! Scene changes can be synced across users with custom networking code using the scene events.

Performance Tips

Preload Settings:

  • Set preloadNext = 1 and preloadPrevious = 0 for linear galleries

  • Set both to 0 to disable preloading (saves memory, slower transitions)

  • Increase preloadConcurrent for faster preloading on good connections

Scene Size:

  • Keep scenes under 10MB for fast loading

  • Use compressed textures

  • Optimize geometry

Loading Scene:

  • Keep loading scenes very small (< 1MB)

  • Use simple geometry and minimal textures

URL Parameters:

  • Set queryParameterName = "" to disable URL syncing if not needed

Debugging

Enable debug mode by adding ?debugsceneswitcher to your URL:

This shows:

  • Scene loading start/finish

  • Progress bars in console

  • Preloading schedule

  • Scene add/remove operations

More Information

Live Example:

Real-World Examples:

API Documentation:

Related Guides:

Last updated