Improbable Icon

SpatialOS Discourse Forums

Testing Matchmaking Server in Unity Editor

I’ve managed to get my matchmaking server working, using the PIT and LT workflow. It works great when testing in the Unity Editor and routes me to the first suitable deployment, but I only connect successfully when the deployment chosen by the matchmaker is the one I ran spatial cloud connect external for.

What’s my best bet for testing this in the editor? Is there a way to have connection open for all the available deployments?

Thanks!

Hi @basil, it sounds like the connection you may be attempting to make is a local connection (hence only the tunneled attempt working). Can you show me your connection logic?

One important part of the player-auth docs is the UseExternalIp = true network parameter.
UseExternalIP signals to the WorkerSDK to use the public IP address of the deployment services rather than the private ones. This is crucial for workers connecting from outside of the cloud network and could be the reason for these connectivity issues.

Hey, thanks for the quick response. Here’s my Connect method in my UnityClientConnector.cs script:

private async void Connect(string PIT, string LT)
    {

        var connParams = CreateConnectionParameters(WorkerUtils.UnityClient);
        connParams.Network.UseExternalIp = true;
        connParams.Network.ConnectionType = NetworkConnectionType.RakNet;
        
        var builder = new SpatialOSConnectionHandlerBuilder()
            .SetConnectionParameters(connParams);

        var initializer = new CommandLineConnectionFlowInitializer();
        
        if (!Application.isEditor) {
            switch (initializer.GetConnectionService())
            {
            
                case ConnectionService.Receptionist:
                builder.SetConnectionFlow(new ReceptionistFlow(CreateNewWorkerId(WorkerUtils.UnityClient),
                    initializer));
                break;
                case ConnectionService.Locator:
                    // Authenticate Locator Flow with PIT and LT
                    var locatorFlow = new LocatorFlow(initializer);
                    locatorFlow.PlayerIdentityToken = PIT;
                    locatorFlow.LoginToken = LT;
                    builder.SetConnectionFlow(locatorFlow);
                break;
                default:
                throw new ArgumentOutOfRangeException();
            }
        }
        else
        {
            Debug.Log(("In Editor - set receptionist flow"));
            var connFlow = new ReceptionistFlow(CreateNewWorkerId(WorkerUtils.UnityClient));
            if (!string.IsNullOrEmpty(RuntimeIp))
            {
                connFlow.ReceptionistHost = RuntimeIp;
            }

            builder.SetConnectionFlow(connFlow);
        }

        await Connect(builder, new ForwardingDispatcher()).ConfigureAwait(false);
    }

Hey @basil, in your else-block (the in-editor flow), you should be connecting via the locator as shown in this doc.

What I think might be happening is that while in-editor, your script is attempting to use the local receptionist which is tunneled to the cloud deployment receptionist from the spatial cloud connect external command.

Hey, in the code from that page in the docs- how do I find LocatorServerAddress and LocatorServerPort?

In the meantime I tried replacing my code in the Else statement to

var locatorFlow = new LocatorFlow(initializer);
locatorFlow.PlayerIdentityToken = PIT;
locatorFlow.LoginToken = LT;
builder.SetConnectionFlow(locatorFlow);

but it’s returning “Failed to create worker”

Hi @basil, the locator host is locator.improbable.io and you can use port 443 (see RuntimeConfigDetails).

Where are you seeing that error? Are you able to see any connection attempt being made to the cloud deployment? I’m not sure what’s present in that initializer, so it may be worth checking to see what’s being passed to the LocatorFlow in that.