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.