Transport Samples
After managing your players with either a matchmaker or lobbies then creating a relay session for them using the Edgegap API, you will need to connect your players to the relay once it is ready. Edgegap offers a specific transport to do just that, and this guide will show you how to implement it in your project. The transport is available here on our GitHub.
With Unity, there currently is a version of the transport for the following netcodes:
Mirror;
Fishnet;
Unity Netcode for GameObjects (NGO).
Adding the transport
After downloading the right transport for your netcode, you need to include it in your project. First, add it to your project files in the following location:
Mirror : add the
Edgegap
folder underAssets/Mirror/Transports
;Fishnet : add the
Edgegap KcpTransport
folder underAssets/Fishnet/Plugins
;NGO : add the
EdgegapRelay
folder underAssets/Edgegap
.
Then, add the EdgegapKcpTransport
script to your NetworkManager
gameObject, make sure to drag that new component in the Transport
property of the gameObject as well.
If the option is present, make sure to disable Relay GUI
in the EdgegapKcpTransport
component of the NetworkManager
. Otherwise, it will interfere when attempting to connect to the relay.
This option is namely present in the Mirror and NGO versions of the transport.
Connecting to the relay
After matchmaking and creating the relay session, use the Edgegap API to determine when the relay is ready to accept connections. Once it is, use the data provided in the API response to set the values of the transport. You will need the following values in the appropriate fields:
the relay's
IP
address is used as thetransport's relay address
;the relay's
client port
value is used as thetransport's relay port
when connecting aclient
;the relay's
server port
value is used as thetransport's relay port
when connecting theserver/host
;the
session authorization token
is used as thetransport's session ID
;the
user's authorization token
is used as thetransport's user ID
.
Each player will have their own unique authorization token, but the session token will remain the same for each player in the session.
Using Mirror
Using Fishnet
Using NGO
Using ApiResponse
Once the values are properly set, use the transport to connect each player to the relay. After a short moment, you will be able to play the game!
Sample projects
The following projects are simple examples that use the Edgegap relay transport.
For them to work properly, open a command prompt terminal and download the project via the git clone [URL]
command. Open the project folder in the editor via the Unity Hub, then change the RelayProfileToken
value in the HelloWorldManager
component of the NetworkManager
gameObject to your own relay profile token.
Last updated
Was this helpful?