Scene Switching - how

Hello,

I like to switch scene when a 3d object is touched. I have looked at the Multi-scene sample but cant figure how it is done. In theory I should be able to attach a script to an object, make it clickable and it should work.

Do I just do this using unity or are there scripts which I can use?

Hi there! I’m an AI-powered assistant here to help you with questions about Needle Engine, three.js, as well as basic Unity or Blender help. Please provide your OS, Needle Engine version, and the Unity version you’re using so I can assist you further!

2 replies left - GPT 4O
thread_RC84KX04C0bw1VbsE8gKRhCo
Reply to this message to continue the conversation

Multiple ways to do it:

  • Use the SceneSwitcher component and call the next() method on the sceneSwitcher when your object is clicked. E.g. if this should apply to ALL objects that are loaded then just add a SceneSwitcher to an Empty Object, add your prefabs to the Scenes Array (just click the Plus button and drag them in the list, can be actual Unity scenes too) and also add a Button component to the same GameObject and add a call to “next()” in the onClick Event
  • If you prefer writing scripts you can load new scenes with “new AssetReference().instantiate({parent: })” for example. Make sure to destroy the spawned instances once you dont need them anymore. There are plenty of examples in the docs/samples or on stackblitz :slight_smile: let me know if you prefer this route so I can send you more

I believe tho that the SceneSwitcher approach does perhaps already all you want and this is what I would suggest you to try first :slight_smile:

Thanks @marcel. I have tried the first method (i.e. using a button and SceneSwitcher). When I run the program, it loads the first scene and then immediately loads the second one. This is what I have included in my button click.

What am I doing wrong?

If you want to change the whole 3D scene you need to slightly restructure your project.

  • Only put the SceneSwitcher in the main scene (the one with the ExportInfo component)
  • Create two separate scenes that you want to switch between (e.g. “AR-Scene” and “YourCurrentMainScene”)
  • Assign both to the main scene with the SceneSwitcher

That’s basically how the sample is also setup if you need a reference :wink:

Ok, thanks. I have done the First two points. I am not sure what is meant by assign both to the main scene by sceneswitcher?

Hi @marcel,

I am observing strange behaviour from the button and the scenswitcher.

1 - Button only loads the next scene if I use SceneSwitcher.selectPrev()

2 - The button text doesn’t show on the scene. (See image)

3 - If I follow your third point, when I switch scene, I won’t be able to come back

I have attached a few screen shots to show what I designed and what I see.



The loading scene should probably not be assigne to AR-scene. The loading scene is what is displayed during loading one of the scenes in the scenes array. You can just leave it empty for now.