Best way to change scenes with VR Multiplayer Template

Hello
I’m trying to create a multiplayer game with the new VR Multiplayer Template and I’m having problems when I try to switch between scenes.
I’m using the “SampleScene” scene as my base scene, which allows different players to access the lobby. From the lobby I want to switch to a different scene and move all the players to the new scene, so that they can play a minigame in isolation from the central lobby.
To do this I’ve created the following method which is called by pressing a button from the lobby:

public class SceneChanger : NetworkBehaviour
{
    public void ChangeScene(string sceneName)
    {
        if (IsServer && !string.IsNullOrEmpty(sceneName))
        {
            var status = NetworkManager.SceneManager.LoadScene(sceneName, LoadSceneMode.Single);
            if (status != SceneEventProgressStatus.Started)
            {
                Debug.LogWarning($"Failed to load {sceneName} " +
                      $"with a {nameof(SceneEventProgressStatus)}: {status}");
            }
        }
    }
}

I’m doing it with LoadSceneMode.Single so that only the new scene is loaded and no elements are duplicated (LoadSceneMode.Additive mixes both scenes).
As a test, I’m trying to load the “BasicScene” scene from the Template, which has XR Interacion Setup, XRI Network Connection Manager and Network Manager VR Multiplayer configured exactly the same as the previous scene. However, when making the change the following error occurs:

This seems to happen because the m_HeadOrigin variable of XRINetworkPlayer is null, while m_LeftHandOrigin and m_RightHandOrigin have been initialized correctly. Here is the code of XRINetworkPlayer

protected virtual void LateUpdate()
{
    if (!IsOwner) return;

    // Set transforms to be replicated with ClientNetworkTransforms
    leftHand.SetPositionAndRotation(m_LeftHandOrigin.position, m_LeftHandOrigin.rotation);
    rightHand.SetPositionAndRotation(m_RightHandOrigin.position, m_RightHandOrigin.rotation);
    head.SetPositionAndRotation(m_HeadOrigin.position, m_HeadOrigin.rotation);
}

I don’t quite understand why this error occurs, and if it is a problem with the ChangeScene method or otherwise it is a problem with the configuration of the target scene.

Could anyone who has worked with VR Multiplayer Template and Netcode tell me the best way to change scenes, and what configuration the target scene should have?
Thank you very much.

I would recommend loading all your managers additively on startup and marking them as DontDestroyOnLoad (XRI Network Game Manager, Network Manager VR Multiplayer, and the XR Interaction Setup (MP Variant)).

Once you connect online you will probably want to set the XRI Network Player Avatar to DDoL as well.

Then make sure whatever scene you are loading doesn’t already contain these objects and you should be good to go.

NOTE: Any scene references to these objects will need to be handled with a lookup on start since they will now be apart of the DDoL scene.

Hopefully that helps, let me know how it goes!

May the odds be ever in your favor!
-Joegre

You know that you can also unload additively loaded scenes?

Doing so gives you full flexibility which content you currently want loaded in a scene or not. Single scene loading always completely destroys the current scene’s content and then loads the entirety of the new scene - with the exception of DDOL objects (that’s a separate, internally handled, always loaded scene).

Because of this single scene loading is more resource intensive and takes longer than additive scene loading.

Regardless, keeping your global objects in DDOL is recommended. If you need to quickly access any of these, rather than making n singleton objects instead make a registry of global object. I call it the Components Registry.