NetworkManager - How to set path of UnityTransport Websocket (TCP)?

Hi, I have a webgl project with a NetworkManager.

After setting the UnityTransport, in my startup script I can set the server address and port like this:

NetworkManager.Singleton.GetComponent<UnityTransport>().ConnectionData.Address = _netcodeUrl;
NetworkManager.Singleton.GetComponent<UnityTransport>().ConnectionData.Port = _netcodePort;

And flag “Use WebSocket” in the inspector.

Now I need to specify a path too, but i cannot understand HOW to set it. I expected something like:

NetworkManager.Singleton.GetComponent<UnityTransport>().ConnectionData.Path = _myPath;

but apparently there is no option like this.

In the UnityTransort manual I find this code:

var settings = new NetworkSettings();
settings.WithWebSocketParameters(path: "/some/path");
var driver = NetworkDriver.Create(new WebSocketNetworkInterface(), settings);

How can i set this driver in the UnityTransport used by NetworkManager?

I find this method:

NetworkManager.Singleton.GetComponent<UnityTransport>().CreateDriver();

where one of the parameters is a Network driver, but I’m not sure if it’s the correct waty to set it, and anyway I cannot understand how to the set the other parameters.

Thanks

I assume what you are trying to do is possible via:

UnityTransport.s_DriverConstructor

@Ezard is absolutely right. This is not an option today in NGO and you need to use a custom driver constructor to accomplish this. (We probably should offer it out-of-the-box in NGO though. I’ll look into this.)

Something like this should accomplish what you want:

public class CustomWebSocketDriverConstructor : INetworkStreamDriverConstructor
{
    public void CreateDriver(
        UnityTransport transport,
        out NetworkDriver driver,
        out NetworkPipeline unreliableFragmentedPipeline,
        out NetworkPipeline unreliableSequencedFragmentedPipeline,
        out NetworkPipeline reliableSequencedPipeline)
    {
        var settings = transport.GetDefaultNetworkSettings();
        settings.WithWebSocketParameters(path: "/YOUR/PATH/HERE");

        driver = NetworkDriver.Create(new WebSocketNetworkInterface(), settings);

        driver.RegisterPipelineStage(new NetworkMetricsPipelineStage());

        transport.GetDefaultPipelineConfigurations(
            out var unreliableFragmentedPipelineStages,
            out var unreliableSequencedFragmentedPipelineStages,
            out var reliableSequencedPipelineStages);

        unreliableFragmentedPipeline = driver.CreatePipeline(unreliableFragmentedPipelineStages);
        unreliableSequencedFragmentedPipeline = driver.CreatePipeline(unreliableSequencedFragmentedPipelineStages);
        reliableSequencedPipeline = driver.CreatePipeline(reliableSequencedPipelineStages);
    }
}

Then simply assign an instance of this class to UnityTransport.s_DriverConstructor before calling any of the start methods on your NetworkManager.

FYI this will be addressed in the next version of NGO (2.11). The path will be settable directly in the connection data.