New VR Multiplayer Template Available

The scene won’t auto load if you rebuilt the library. Here is a great tip, if you are ever unsure of the “start scene” check the build settings :smiley:

Is there a way to disable the UGS check so that I can truly run this as a LAN?
Following the link it still has to check the UGS and pops up an error when you try to launch

[XRMultiplayer] [Network Game Manager] Project has not been linked to Unity Cloud.
The VR Multiplayer Template utilizes Unity Gaming Services and must be linked to Unity Cloud.

Just tried to use the template in Unity 6000.0.23.
Testing in the editor with Multiplayer Play Mode 1.3.1.
I set different player tags, so I’ll get different PlayerID for the different instances.

It works well when I use the default Lobby/Transport/RelayServer settings.
But when I try to set the RelayServer secure setting to true, and/or the RelayServer+Transport to use WSS+WebSocket, I get random errors.
Both in Editor and Desktop.

Those are the multiplayer related packages and versions in the project

    "com.unity.multiplayer.center": "1.0.0",
    "com.unity.multiplayer.playmode": "1.3.1",
    "com.unity.netcode.gameobjects": "2.0.0",
    "com.unity.render-pipelines.universal": "17.0.3",
    "com.unity.services.authentication": "3.3.3",
    "com.unity.services.lobby": "1.2.2",
    "com.unity.services.relay": "1.1.1",
    "com.unity.services.vivox": "16.5.0",
    "com.unity.transport": "2.3.0",

Is the netcode stack supports websocket? Does it support running on web browser?
I see contradicting answers when reading the docs and the forums.
I want to be able to run it on web, so I’ll be able to add support for WebXR.

Thanks

So glad you are looking into adding WebXR support! This was not an initial build target for the VR Multiplayer Template, however it should technically be possible.

A few things to note of importance:

  • The Microphone API is used in the OfflinePlayerAvatar script and will need some #if !PLATFORM_WEBGL defines to prevent that from executing.
  • The LobbyUI and PlayerSlot scripts are using WebSocketSharp. You can remove that namespace (looks like probably an oversight) and just use string.IsNullOrEmpty.
  • You will also get some warnings on build completion for things like:

Embedded video clips are not supported by the WebGL player: Assets/VRMPAssets/MiniGames/MiniGameVideos/Whack_A_Pig_Minigame_Onboarding_Video.mp4.
Use the Video Player component’s URL option instead.

Thanks for reaching out and I can’t wait to see how it goes! Let me know if you hit any additional snags.

Thanks!
Those were quick fixes that I done already.
I also had to disable Vivox.

My issue is with the multiplayer part.
As mentioned, I wasn’t able to use WebSockets with this sample.
Maybe there are bugs in the combination of Unity+Packages versions that I used?
Do you know which versions of Unity and the multiplayer packages will work for sure with Websockets?

I modified the Lobby script to create RelayServerData object with isSecure and isWebSocket set to true, and updated the Transport script to useWebSocket true.
But once isSecure=true or isWebSocket+useWebSocket are true, the connections fails in different ways even on the editor and on desktop builds.

Managed to use WebSockets in Desktop+Web.

What went wrong:
I went over docs and forum posts, and figured that in order to run Unity Netcode on web, I need to use WebSockets with SSL (WSS), I saw that in order to do that, I need to make sure both the UnityTransport component and RelayServerData configured to use WebSockets, and that the connection needs to be secured (configured on RelayServerData).

I saw that LobbyManager calls UnityTransport methods to generate RelayServerData.
And there I saw that the RelayServerData was configured as isSecure=false and isWebSocket=false.
So I added those methods to LobbyManager and used them instead. It didn’t work.

void SetHostRelayData(string ipAddress, ushort port, byte[] allocationId, byte[] key, byte[] connectionData)
{
    SetRelayServerData(ipAddress, port, allocationId, key, connectionData, null);
}
  
void SetClientRelayData(string ipAddress, ushort port, byte[] allocationId, byte[] key, byte[] connectionData, byte[] hostConnectionData)
{
    SetRelayServerData(ipAddress, port, allocationId, key, connectionData, hostConnectionData);
}
  
void SetRelayServerData(string ipv4Address, ushort port, byte[] allocationIdBytes, byte[] keyBytes, byte[] connectionDataBytes, byte[] hostConnectionDataBytes = null)
{
    var hostConnectionData = hostConnectionDataBytes ?? connectionDataBytes;
    bool isSecure = true;
    bool isWebSocket = true;
    RelayServerData relayServerData = new RelayServerData(ipv4Address, port, allocationIdBytes, connectionDataBytes, hostConnectionData, keyBytes, isSecure, isWebSocket);
    m_Transport.UseWebSockets = isWebSocket;
    m_Transport.SetRelayServerData(relayServerData);
}

Even when I switched only isSecure to true and in desktop/editor mode, it didn’t work. And it was weird, as it’s the only value I changed.

Then I read more, and noticed this warning in one of the docs:

Warning: You won’t be able to connect to the Relay server if there’s a mismatch between the information provided through SetRelayServerData / SetRelayClientData and the information obtained from the allocation. For example, you’ll receive a “Failed to connect to server” error message if the isSecure parameter doesn’t match.

One of the easiest ways to prevent this from happening is to build the RelayServerData directly from the allocation. However, you must use Netcode for GameObjects (NGO) version 1.1.0 or later.

So my guess was, that even if I think that all parameters match, something might be wrong.

I switched to use those methods instead:

void SetHostRelayData(Allocation allocation)
{
    RelayServerData relayServerData = new RelayServerData(allocation, "wss");
    m_Transport.UseWebSockets = true;
    m_Transport.SetRelayServerData(relayServerData);
}
  
void SetClientRelayData(JoinAllocation joinAllocation)
{
    RelayServerData relayServerData = new RelayServerData(joinAllocation, "wss");
    m_Transport.UseWebSockets = true;
    m_Transport.SetRelayServerData(relayServerData);
}

And it worked!:tada:
I tested on Editor, Desktop and Web, and it worked on all.

  • I also set the Allow Remote Connections? option on the UnityTransport component to true, it’s needed for local tests as well.
  • If using the Multiplayer Play Mode in editor, need to configure tags for the different players.

Now to add the WebXR Export packages to add WebXR support :slight_smile:
I’ll live stream my attempt on Youtube if someone wants to watch.

2 Likes

@Joegre is there a change log available online for the template?

Managed to run it in WebXR and test with a few people, including voice chat.

For voice chat had to use JoinGroupChannelAsync instead of JoinPositionalChannelAsync, and not everyone were able to join with voice.
Also those in web have the AudioEnergy always 0, so no indication of who is talking.

Now the thing that is missing is hosting dedicated server build, as those on web can’t create rooms.

3 Likes

This is awesome. Thanks Oren

i have been trying to upload this vr multiplayer template on github but the files are too large so it asks me to use git LFS.Do you use the same or is there any other way to work around it like you said reasonable .gitignore file? Sorry i am a beginner with unity and git both

Yes you want to use git LFS.

I’d recommend getting used to using it, it’s immensely helpful and is really simple to use. Most games that use git will use LFS as well. It’s also installed by default with newer versions of git.

Tried out this template today and must say really well done! Everything we need to get started on an upcoming project. Is it possible to integrate the Meta Avatars with this if building for quest?