How do we setup our own Relay Server with NGO?

How do we go about setting up our own relay server with the default Transport?

All of the docs seem to be unclear about how to do anything on your own and focus mainly on how the Relay service from Unity can handle this for them - but the fee scaling is wild. Is there a reasonable simple way to handle implementing your own relay server and just piping the transport through it?

If you are going to release it on Steam, you can use the facepunch transport. It is free.

The default transport does not support setting up your own Relay server. It supports either direct connections (with IP addresses) or connections through the Unity Relay service.

1 Like

Are there any alternative transports available that allow custom relay servers or should we use a different networking system?

You can peruse the list of available community-supported transports here. I’m not familiar with all of them. It’s possible one of them allows using a custom relay server. It’s also possible to write a custom transport, if none of these fit your specific needs.

2 Likes

Kcp transport is built to support any relay.
MIT licensed so you should be able to adapt it to NGO too.

1 Like

Thank you both for your prompt responses.

For future reference when exploring NGO with Relay, the relevant provided example code in NGO for Relay works but you do have to still update the Transport with the relay data.

        public static async Task<RelayHostData> HostSession(bool offline = false, int maxConn = 20)
        {
            if (offline)
            {
                Singleton.StartHost();
                return new RelayHostData();
            }

            await UnityServices.InitializeAsync();
            if (!AuthenticationService.Instance.IsSignedIn)
            {
                await AuthenticationService.Instance.SignInAnonymouslyAsync();
            }

            Allocation allocation = await Unity.Services.Relay.RelayService.Instance.CreateAllocationAsync(maxConn);
            RelayHostData data = new RelayHostData
            {
                IpAddress = allocation.RelayServer.IpV4,
                Port = (ushort)allocation.RelayServer.Port,

                AllocationId = allocation.AllocationId,
                AllocationIdBytes = allocation.AllocationIdBytes,
                ConnectionData = allocation.ConnectionData,
                Key = allocation.Key,
            };

            data.JoinCode = await Unity.Services.Relay.RelayService.Instance.GetJoinCodeAsync(data.AllocationId);

            Singleton.GetComponent<UnityTransport>().SetRelayServerData(new RelayServerData(allocation, "dtls"));
            Singleton.StartHost();
            return data;
        }
        public static async Task<RelayJoinData> JoinSession(string joinCode)
        {
            await UnityServices.InitializeAsync();
            if (!AuthenticationService.Instance.IsSignedIn)
            {
                await AuthenticationService.Instance.SignInAnonymouslyAsync();
            }

            JoinAllocation allocation = await Unity.Services.Relay.RelayService.Instance.JoinAllocationAsync(joinCode);
            RelayJoinData data = new RelayJoinData
            {
                IpAddress = allocation.RelayServer.IpV4,
                Port = (ushort)allocation.RelayServer.Port,
                AllocationId = allocation.AllocationId,
                AllocationIdBytes = allocation.AllocationIdBytes,
                ConnectionData = allocation.ConnectionData,
                HostConnectionData = allocation.HostConnectionData,
                Key = allocation.Key,
            };

            Singleton.GetComponent<UnityTransport>().SetRelayServerData(new RelayServerData(allocation, "dtls"));
            Singleton.StartClient();
            return data;
        }

What transport layer did you use, did you write your own?

Kindly share which transport layer did you use, did you write your own?

Regular Unity Transport.

I used Photon-Realtime and it work like a charm! Now we are using out project both Netcode for GameObject and Photon-Realtime together.

Thank you very much!