Distributed authority WebGL support

Hey,

Is it possible to use distributed authority model on WebGL? I’ve been trying to get this minimal DA sample working on WebGL, but it just doesn’t seem to work.

I guess I should enable ‘Use Web Sockets’ on transport, but that doesn’t help either and when I set it ‘ON’, it also stops working when running in editor and I get this error:

‘Transport is configured to use WebSockets, but Relay server data isn’t. Be sure to use “wss” as the connection type when creating the server data (instead of “dtls” or “udp”).’

Where can I set this connection type to ‘wss’?

I’m testing with this NetcodeForGameObjectsExample/DistrubutedAuthority sample

You can set it in the server component settings, as well as potentially by code

Hey, thanks for reply. I have no idea where to find this ‘server component’ in settings. I tried to set this relay thing in code, but it didn’t help at all. Distributed authority should work on WebGL right?

There will be a gameobject with it on

There is certainly not. Have you tried the sample yourself? Also code to create / join session is very simple and has basically three lines for creating or joining session:

await UnityServices.InitializeAsync();
await AuthenticationService.Instance.SignInAnonymouslyAsync();
var options = new SessionOptions()
{
        Name = sessionName,
        MaxPlayers = m_MaxPlayers
}.WithDistributedAuthorityNetwork();
m_Session = await MultiplayerService.Instance.CreateOrJoinSessionAsync(sessionName, options);

and that’s it.

There is look … taken from your own picture

Yes, but I tried to explain on my first post, that this doesn’t work. Not in editor and not in WebGL build

1 Like

I think that in the current packages combination, WebSockets are broken.
I also tried to enable WebSockets in Transport, and use WebSocket in RelayServerData in Unity6 + Latest packages versions, and it didn’t work even on editor and desktop builds.

@bugfinders on what Unity version and packages versions have you managed to use WebSockets and run it on web browser?

1 Like

I havent tried since 6 went live last week, but i did during the pre release times. I’ll try carve some time later to fire up unity and poke it

2 Likes

I managed to use WebSockets in Unity 6. At least for my use case.

The error you got:

‘Transport is configured to use WebSockets, but Relay server data isn’t. Be sure to use “wss” as the connection type when creating the server data (instead of “dtls” or “udp”).’

Means that you are using RelayServer.
Look in your code if there’s somewhere that generates RelayServerData, by calling SetHostRelayData, SetClientRelayData or SetRelayServerData of UnityTransport.
If it does, you want to generate the RelayServerData in your own code, instead of using those methods.

Something like

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);
}

More info and how I got to this solution, in this comment: New VR Multiplayer Template Available - #28 by De-Panther

1 Like

Hey, Are you using Distributed Authority as a Network Topology?

Anyways, in my code there’s no RelayServer settings, but I guess DA mode uses always RelayServer.

I looked com.unity.services.multiplayer package inner workings and when Distributed Authority network settings are created in ConnectionModule.cs, it sets RelayServerData like this:

case NetworkType.DistributedAuthority:
                    {
                        Logger.LogVerbose($"Setting up DA Network");
                        DaHandler = m_DaBuilder.Build();
                        await DaHandler.CreateAndJoinSessionAsync(m_Session.Id, ConnectionInfo.Region);
                        allocationId = DaHandler.AllocationId.ToString();

                        var connectPayload = DaHandler.GetConnectPayload();
                        await SetDistributedAuthorityConnectHash(connectPayload);

                        var networkConfiguration = new NetworkConfiguration(
                            networkRole,
                            NetworkType.DistributedAuthority,
                            DaHandler.GetRelayServerData(MPConstants.DTLS),
                            connectPayload.SerializeToNativeArray());
                        await SetupConnectionAsync(networkConfiguration);
                        ConnectionMetadata = new ConnectionMetadata()
                        {
                            Network = NetworkType.DistributedAuthority,
                            RelayJoinCode = DaHandler.RelayJoinCode
                        };
                        break;
                    }

I have no idea, if I can override this RelayServerData in my code though or should I even? If I’m running this on WebGL target and tap ‘Use Web Sockets’, I should expect that it uses websockets automatically for all things as there’s no other way.

No. I only used Unity’s VR Multiplayer template to test it.
If Distributed Authority should work on web, what you describe sounds like a bug, and you should report it.

And I agree with you that the process of switching using WebSockets on/off should be simpler.

1 Like

Alright, tested the latest update and it works now perfectly without issues. Just tap the ‘Use Web Sockets’ and that’s it:
https://docs.unity3d.com/Packages/com.unity.services.multiplayer@1.0/changelog/CHANGELOG.html#102---2024-10-28

1 Like

I seem to be running into this same issue, even with the updated multiplayer services package.

I am following this very simple example:

But when I try to run it in the editor, I get this:

Use websockets IS checked, not sure what is going on. Here are my settings:

Thanks for any help

I dont think its about the settings here, more the code to join, as per above, it references relay, you need to set transport to wss etc

Thanks for the reply, any idea why I am getting this error:

Relay server data indicates usage of WebSockets, but “Use WebSockets” checkbox isn’t checked under “Unity Transport” component

I have “use web sockets” checked, and I thought that was how you set transport to wss? Unless I am missing something

I always had to do more, and it seems it wasnt just me

link to relevant post above Distributed authority WebGL support - #10 by De-Panther

Thanks again, this was just a bog standard project with zero custom code, just the packages from unity and following the tutorial from unity, so I sent in a bug report. As far as I can tell, there seems to be a problem when you choose protocol type, it uses “relay unity teleport” even if you have “unity teleport” selected.

Has this changed with the new unified multiplayer package?

It requires RELAY_SDK_INSTALLED. The com.unity.services.relay package

1 Like