Hello everyone.

The Mixed Reality Forums here are no longer being used or maintained.

There are a few other places we would like to direct you to for support, both from Microsoft and from the community.

The first way we want to connect with you is our mixed reality developer program, which you can sign up for at https://aka.ms/IWantMR.

For technical questions, please use Stack Overflow, and tag your questions using either hololens or windows-mixed-reality.

If you want to join in discussions, please do so in the HoloDevelopers Slack, which you can join by going to https://aka.ms/holodevelopers, or in our Microsoft Tech Communities forums at https://techcommunity.microsoft.com/t5/mixed-reality/ct-p/MicrosoftMixedReality.

And always feel free to hit us up on Twitter @MxdRealityDev.

How to change back and forth between scenes?

dbarrettdbarrett ✭✭✭
edited April 2018 in Questions And Answers

I am trying to change scenes back and forth, however, I have run into a problem because the InputManager persists and it complains because my Camera and Cursor have changed. So I made the Camera and Cursor persist but, now when I go back to the first scene it complains again for having two cameras and two cursors. How should I go about fixing this?

AR Developer


Best Answer


  • I have the exact same problem.. Did you solve it @dbarrett ?

  • InputManager and the camera/cursor etc all have DontDestroyOnLoad:

    This means that they aren't destroyed when you switch between scenes.

    You either need to prevent them from doing that (removed the calls to DontDestroyOnLoad) or you need to ensure you don't load a second scene with these objects in them or you will end up with duplicates.

    I'd suggest either removing these objects from your first scene and loading their prefabs manually or I'd suggest splitting your first scene into two scenes.

    For example, you could make a scene with just the InputManager, Camera, Cursor, etc. Have the project load this first and then load your first scene (which would not have an InputManager, Camera, Cursor, etc). That way you could leave the first scene and come back without loading all of those behaviors a second time.


  • Hi Mark, thanks for the response. I tried your solution: The problem occurs when you go back and forth between scenes. To be more precise: 1st scene has Camera, InputManager, Cursor. Switching to 2nd scene is no problem- the objects are retained. Switching back to 1st scene - everything disappears again.

  • That sounds different than what @dbarrett is saying. He is saying he is getting duplicate cameras/etc. which means the same scene is reloading and adding a second set.

    I am not sure why loading scene 1 a second time would be any different.
    1. What function are you using to load the scene?
    2. In Unity's hierachy are your camera/inputmanager/etc located under the 'DontDestroyOnLoad' section?


  • I tried both ways: First way:
    So when I have 2 scenes with InputManager, Camera, Cursor in it. The transition from 1st to 2nd (via LoadScene.Single) shows me the 2nd scene but with different positions of camera, cursor, InputManager. I suspect the duplicate problem here as @dbarett

    Second way: 1st scene has InputManager, Camera, Cursor. 2nd scene has nothing except for other game objects. Transition from 1st to 2nd is fine, 2nd to 1st leaves the Cursor somewhere else. It used to interact with the Canvas but it no longer does. It is for example hidden behind the canvas. Do Canvas settings also change because the Camera is somehow messed up?

  • Make 3 scenes. 1st with InputManager, Camera, Cursor.

    2nd and 3rd without.

    Load the first as your project loads and then add the 2nd scene. Now you should be able to switch between 2nd and 3rd no problem.

    If you do hit problems then please look at your DontDestroyOnLoad section of your scene hierarchy as shown in the screenshot above. If you have 2 of these objects then you will absolutely have issues.


  • codeholocodeholo
    edited July 2018

    If you do hit problems then please look at your DontDestroyOnLoad section of your scene hierarchy as shown in the screenshot above. If you have 2 of these objects then you will absolutely have issues.

    --- this is exactly what's happening. How do I not see this error?

  • Thanks Mark. Did all of that. My issue was more of this https://github.com/Microsoft/MixedRealityToolkit-Unity/pull/1575 And I found out the canvas elements weren't appearing because the camera is not using the MRCamera which is from the first scene. I modified the CanvasHelper script which assigns the world camera to MRCamera and now it works :)

  • dbarrettdbarrett ✭✭✭

    ^ Making 3 scenes would fix it.

    Scene 1: Has InputManager, Camera, Cursor
    Scene 2: NO InputManager, Camera, Cursor
    Scene 3: NO InputManager, Camera, Cursor

    Load Scene1 first. Then you can switch between scene 2/3 as needed.


    @codeholo that is how I solved this problem. I thought I had answered it myself but, I must have forgot to.

    AR Developer

  • BWattBWatt
    edited September 2018

    I'm trying to do as shown above, but when I get to scene 2 or 3, I get errors from the MixedRealityTeleport script that the GameObject has been destroyed (teleport marker), and then a bunch of errors about the Animator is destroyed and trying to access it. I see the Camera and Input Manager in the DontDestroyOnLoad but not the Cursor... what did I miss? Any help would be greatly appreciated...

    Just to clarify, I do get the controller models and the camera works fine, I can turn and go backwards, I just don't get a ground marker when I flick the controller joystick forward, so I cannot move forward, just turn and go backwards.

  • The cursor does not have a DontDestroyOnLoad called on it. You will either need to include the cursor in each of your scenes or you will need to call DontDestroyOnLoad on that game object.



  • BWattBWatt
    edited October 2018

    I've tried both, adding the default cursor to each page, and adding the DontDestroyOnLoad to the awake function of the base cursor (separately, not at the same time), and I still get an error that mixed reality teleport cannot find the game object. The cursor is showing in the DontDestroyOnLoad during runtime... do I need to make modifications to MixedRealityTeleport?

  • I don't see Cursor mentioned in the MixedRealityTeleport class. Perhaps I am on a difference version.

    Please post the error log so we can check out the line number/etc.


Sign In or Register to comment.