Hello! i know that the template is pretty new, but i want to know is someone has been able to modify it so that it can run on local and it doesnt depend on the unity lobby system. Thanks!
Officially we currently only support the UGS implementation. We have on our roadmap to include a dropdown option to choose hosting (local, cloud, dedicated, etcā¦), but for the initial release itās only the UGS implementation. I have no idea on timeline for the update, but Iād say at least 6+ months as itās a lower prio (for now).
That being said, unofficially Iāve played around running it with no internet and LAN only. There are a few minor code changes that need to happen, but it should be pretty manageable. Iād recommend creating a new script that inherits from the XRINetworkGameManager
and setting up some LAN only connection functions that bypass the LobbyManager
all together. Fortunately with LAN you should already know what IP / port you are connecting to and can do that directly by setting the values in the Unity Transport
(either in inspector or in code), then calling NetworkManager.Singleton.StartHost
(or StartClient
) respectively.
Thank You! Actually, yesterday i was looking out for solutions and i did that, also i āMockā the lobby manager because some other componentes use it to retrieve the id.
XRINetworkGameManager:
public virtual void StartHost()
{
// Search for a NetworkManagerVRMultiplayer in the scene.
NetworkManagerVRMultiplayer networkManager = FindObjectOfType<NetworkManagerVRMultiplayer>();
if (networkManager == null)
{
Utils.Log($"{k_DebugPrepend}No NetworkManagerVRMultiplayer found in scene.", 2);
return;
}
else
{
Utils.Log($"{k_DebugPrepend}Starting Host.");
// String hostId = NetworkManager.Singleton.LocalClientId.ToString();
Utils.Log($"{k_DebugPrepend}Host ID: {0}");
// Mockeamos el lobby, ya que no estamos utilizando el servicio de lobbies.
m_LobbyManager.MockLobby("0");
NetworkManager.Singleton.StartHost();
}
}
LobbyManager:
public void MockLobby(string HostId)
{
m_ConnectedLobby = new Lobby(id: "mock", name: "mock", hostId: HostId, lobbyCode: "mock", maxPlayers: 20, isPrivate: false, data: new Dictionary<string, DataObject>());
}
this is a very simple workaround, and it works!
if you could give me any hint to improve this let me know, and thank you again for your response.
This seems like a great workaround, ship it!
Only thing Iād possibly suggest, you donāt need the FindObject
call at the top. Iād probably just check NetworkManager.Singleton == null
as the NetworkManagerVRMultiplayer
inherits from the base NetworkManager
.
oh right. Thanks!
Noob question but how do you inherit from the XRINetworkGameManager
with italovs recomended script?
If I try public class XRINetworkLANManager : XRINetworkGameManager
it says
Assets\VRMPAssets\Scripts\Network\NetworkManagers\XRINetworkLANManager.cs(14,26): error CS0115: āXRINetworkLANGameManager.StartHost()ā: no suitable method found to override
Are you adding this StartHost() right in the XRINetworkGameManager?
Hi! This is my LocalXRINetworkGameManager.cs Script that inherits from XRINetworkGameManager Script:
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Unity.Netcode;
using Unity.Services.Lobbies.Models;
using Unity.XR.CoreUtils.Bindings.Variables;
using UnityEngine;
using Unity.Services.Lobbies;
using UnityEditor;
namespace XRMultiplayer
{
// #if USE_FORCED_BYTE_SERIALIZATION
// /// <summary>
// /// Workaround for a bug introduced in NGO 1.9.1.
// /// </summary>
// /// <remarks> Delete this class once the bug is fixed in NGO.</remarks>
// class ForceByteSerialization : NetworkBehaviour
// {
// NetworkVariable<byte> m_ForceByteSerialization;
// }
// #endif
/// <summary>
/// Extends the NetworkGameManager to manage a LOCAL networked game session.
/// </summary>
public class LocalXRINetworkGameManager : XRINetworkGameManager
{
/// <summary>
/// Lobby Manager handles the Lobby and Relay work between players.
/// </summary>
// public new LobbyManager lobbyManager => m_LobbyManager;
// LobbyManager m_LobbyManager;
const string k_DebugPrepend = "<color=#FAC00C>[Local Network Game Manager]</color> ";
/// <summary>
/// Start the local networked game session as a host.
/// </summary>
/// <remarks>
/// This method searches for a NetworkManagerVRMultiplayer in the scene and starts a host session.
/// </remarks>
public virtual void StartHost()
{
// Search for a NetworkManagerVRMultiplayer in the scene.
// NetworkManagerVRMultiplayer networkManager = FindObjectOfType<NetworkManagerVRMultiplayer>();
NetworkManager networkManager = NetworkManager.Singleton;
if (networkManager == null)
{
Utils.Log($"{k_DebugPrepend}No NetworkManagerVRMultiplayer found in scene.", 2);
return;
}
else
{
Utils.Log($"{k_DebugPrepend}Starting Host.");
// String hostId = NetworkManager.Singleton.LocalClientId.ToString();
Utils.Log($"{k_DebugPrepend}Host ID: {0}");
// Mockeamos el lobby, ya que no estamos utilizando el servicio de lobbies.
// m_LobbyManager.MockLobby("0");
NetworkManager.Singleton.StartHost();
}
}
/// <summary>
/// Start the local networked game session as a client.
/// </summary>
/// <remarks>
/// This method searches for a NetworkManagerVRMultiplayer in the scene and starts a client session.
/// </remarks>
public virtual void StartClient()
{
// Search for a NetworkManagerVRMultiplayer in the scene.
// NetworkManagerVRMultiplayer networkManager = FindObjectOfType<NetworkManagerVRMultiplayer>();
NetworkManager networkManager = NetworkManager.Singleton;
if (networkManager == null)
{
Utils.Log($"{k_DebugPrepend}No NetworkManagerVRMultiplayer found in scene.", 2);
return;
}
else
{
Utils.Log($"{k_DebugPrepend}Starting Client.");
String clientId = NetworkManager.Singleton.LocalClientId.ToString();
Utils.Log($"{k_DebugPrepend}Client ID: {clientId}");
// Mockeamos el lobby, ya que no estamos utilizando el servicio de lobbies.
// m_LobbyManager.MockLobby("0");
NetworkManager.Singleton.StartClient();
}
}
}
}
It should work on your project.
And I take it you are adding your MockLobby() right in the Lobby Manager as the script adds a lobby manager to the inspector when applied to a game object?
Yea, so the XRINetworkGameManager requieres the lobbyManager to exists in the GameObject (as you can see in the script)
So you need to add the MockLobby(string HostId) function inside the LobbyManager Script
This is because the VoiceChatManager Script needs some info from the lobby which you are not going to use since you are playing in lan without the need of internet, so you just can āMock Itā without any problem.
Also, you can just delete the VoiceChatManager component from the GameObject (As you can see in the second picture), if you do this, you dont need to Mock the lobby, and thats why it is commented in the recent code snippet:
else
{
Utils.Log($"{k_DebugPrepend}Starting Host.");
// String hostId = NetworkManager.Singleton.LocalClientId.ToString();
Utils.Log($"{k_DebugPrepend}Host ID: {0}");
// Mockeamos el lobby, ya que no estamos utilizando el servicio de lobbies.
// m_LobbyManager.MockLobby("0");
NetworkManager.Singleton.StartHost();
}
In this way, the Mock function never gets called!
Awesome! Thanks for the help and explanation!
Sorry to bother you again. I just got back to this and was wondering what you put in the MockLobby(string HostId) function? If you donāt add the mocking and just diable the Voice Chat manager you have to do other things to the Player Menu UI in the Multiplayer Demo scene as its Player options script calls the VoiceChatManager. Disabling the Player Menu UI messes up other aspects and then VR never initializes in the headset so I think mocking may be simpler then disabling all the voice chat calls but Iām unsure of how to do that because when I put:
public void MockLobby(string HostId)
{
m_ConnectedLobby = new Lobby(id: "mock", name: "mock", hostId: HostId, lobbyCode: "mock", maxPlayers: 20, isPrivate: false, data: new Dictionary<string, DataObject>());
}
Even as a public void I get errors that it is not accessible
error CS0122: āXRINetworkGameManager.m_LobbyManagerā is inaccessible due to its protection level
Edit: I realized I needed to go into the root LocalXRINetworkGameManager and set LobbyManager m_LobbyManager; to public.
That got rid of all errors but the game demo never starts VR? It just plays in the Editor and seems to fail at connecting Host or Client with the function calls while never loading anything to the HMD?
Thanks.
Hi!
That got rid of all errors but the game demo never starts VR? It just plays in the Editor and seems to fail at connecting Host or Client with the function calls while never loading anything to the HMD?
Even if it canāt connect as Host or Client, the VR should be initialized as soon as you click play on the editor, you can try building the game directly into the headset (if you are using Oculus Quest 2 or 3 itās pretty straightforward), and if you want to test in the editor you need to use Meta Quest Link. Also, if you want to test it without the headset you can add the XR Device Simulator in the scene.
Are you inside the SampleScene? (Below)
The workaround for the LAN connection worked for me, but in another scene that is called āBasic Sceneā that is also included inside the VR MP Template. (Below) The one in the image is modified but it looks something like that.
Iāve never tried the LAN Connection in the Sample Scene.
Also, remember to use the StartHost() and StartClient() Funcs of the LocalXRINetworkGameManager class
I tried it in the Sample scene but also just tried in the Basic Scene
No luck. I just get an error about needing to connect to the cloud
Which shouldnāt be needed as this is LAN and I donāt want cloud services.
Iām using a cabled Valve Index headset and while I have a project made with Auto Hands VR and Hurricane VR that both work the Unity XRIT is not working. I even just made a Core VR scene with the XR IT and it wont load in the headset either?
The settings for OpenXR should be fine so Iām not sure what Iām missing
Edit: Something must be messed up with my PC as I cant run GitHub - Unity-Technologies/XR-Interaction-Toolkit-Examples: This repository contains various examples to use with the XR Interaction Toolkit in my headset anymore either and I was able to before. Now even Hurricane VR and Auto Hands projects have stopped working. I guess I need to reboot and troubleshoot my HMD.
Oh, i think i linked the project to unity cloud the first time i opened the template to try the sample scene. Then i did the things that we talked for the Lan connection, and it worked. But the project has been linked to the unity cloud, although it doesnāt use it, because i can run the basic scene with the wifi turned off, and i can start a host and then connect clients without any problem. So, i think it depends on the unity cloud even if you are not using it.
Actually, i forgot that Unity Cloud part, so i dont know if there is a way to skip that setup part.
For the Valve Headset, Iām not familiarized with that. I canāt help you with that part.
ive only used the Oc Quest 2 with OpenXR and it works.
Remember to add it to the openxr setting.
Ok That wont work for me. I am testing this so that I can eventual build it in a closed off business network that can not connect to the cloud at any point.
For the headset something is definitely wrong on my machine as I have multiple projects that opened before and no only one opens and another only gets audio while the rest never seem to hit the HMD at all so something got corrupted
(Controllers and XR settings all set but something else is wrong and new projects are no longer generating .sln or .proj files either.)
Anyways Thanks for your help!
No problem!
Good luck