
This guide shows you how to add Edgegap's Distributed Relays to a peer-to-peer Unity game built with Mirror: one player hosts, the others join through a relay near them, with no port forwarding and no NAT issues.
A relay is not a game server. It forwards traffic between players while the host player's game runs the match. Edgegap assigns each session to the best available relay for its players from a simple API call, billed while the session is open. If you'd rather run the match on an authoritative server that no player controls, see Mirror Networking instead.
This guide covers:
Getting your relay token
Connecting your coding agent to Edgegap (optional)
Adding Edgegap's relay transport to Mirror
Creating a relay session from your backend
Connecting the host and players
Grouping players and adding late joiners
Testing with two players
You can do it two ways, and mix them:
With a coding agent. Any AI coding assistant can write the backend call and the connection code from the prompts below. Connected to the Edgegap MCP server, it can also create, read and delete relay sessions for your tests.
By hand. Every step below also works without an agent.
Here, we use Edgegap's Mirror relay sample. The relay also works with Netcode for GameObjects and Fish-Networking, through their own transports.
1. Before you start
A free Edgegap account. Verify your email. No credit card is needed to test.
A Unity project using Mirror, where one player hosts (host and client in the same game). A Unity LTS version is recommended.
A relay profile token. In the dashboard, open Relays, create a relay profile and copy its token. It isn't your Edgegap API token: standard API tokens don't work with the relay API.
A place to keep that token off players' machines: your lobby, your matchmaker or a small backend service. Anyone holding it can create sessions on your account.
For the agent path: an Edgegap API token, from Dashboard → User Settings → Tokens. It is organization-wide, so treat it like a password: never put it in your project, your game client or a chat.
Git: cloning the sample needs a Git client. macOS usually has one already (Xcode Command Line Tools); on Windows, install Git.
2. Connect your coding agent to Edgegap
Skip this step if you're doing everything by hand.
The Edgegap MCP server lets your agent work on your account. For relays, it can create a test session for a list of player IPs, read it, authorize a late joiner and delete it. It may also point out when an authoritative server would suit your game better: that's expected, relays are for games built host-client.
Claude Code: install the Edgegap plugin. It adds both the MCP server and the skills, and asks for your API token during install (stored in your system's credential store):
/plugin marketplace add edgegap/llm-agent-skills, then /plugin install edgegap@edgegap. Restart the session.
Only want the MCP server, without the plugin? Run this in your own terminal instead: claude mcp add --transport http edgegap https://mcp.edgegap.dev/mcp -H "Authorization: token YOUR_EDGEGAP_API_TOKEN" --scope user. Don't do both, or you'll have two edgegap servers.
Cursor, VS Code and other clients that send headers: add https://mcp.edgegap.dev/mcp with the header Authorization: token YOUR_EDGEGAP_API_TOKEN, and install the skills with npx skills add edgegap/llm-agent-skills --skill "*".
Claude Desktop: custom connectors can't send the header, so use the local server instead (Node 18+): { "mcpServers": { "edgegap": { "command": "npx", "args": ["-y", "@edgegap/mcp"] } } }. It asks for the token on first use.
Check it works:
Which Edgegap tools do you have for relay sessions?
It should list tools to create, read, authorize on and delete relay sessions.
3. Add Edgegap's relay transport to Mirror
Download Edgegap's transports from distributed-relay-examples and copy the
Edgegapfolder intoAssets/Mirror/Transports.Select your NetworkManager game object and add the EdgegapKcpTransport component.
Drag that component into the NetworkManager's Transport field.
If the component shows Relay GUI, disable it: it interferes with relay connections.
Using the sample? It's already set up: clone https://github.com/edgegap/unity-mirror-relay-sample and open the folder in Unity Hub.
4. Create a relay session from your backend
Your backend creates one session per match, for every player's public IP, host first, from a simple API call:
POST https://api.edgegap.com/v1/relays/sessions with the header Authorization: Token YOUR_RELAY_PROFILE_TOKEN and the body { "users": [ { "ip": "1.1.1.1" }, { "ip": "2.2.2.2" } ] }.
The relay takes a moment to assign. Poll GET https://api.edgegap.com/v1/relays/sessions/{session_id} every 2 seconds until ready is true, or pass a webhook_url when you create the session and Edgegap calls it once the relay is assigned, or if assignment fails.
Once ready, the response holds everything players need:
relay.ipandrelay.ports: the relay address, with a server port for the host and a client port for everyone else.authorization_token: the session token, the same for every player.session_users[].authorization_token: one token per player.
Send each player only their own values: the relay address, their port, the session token and their own token. The relay profile token never leaves your backend.
With your agent:
Write an endpoint in my backend that creates an Edgegap relay session: POST https://api.edgegap.com/v1/relays/sessions with the header Authorization: Token, read from the RELAY_PROFILE_TOKEN environment variable, and one user per player IP, host first. Poll GET /v1/relays/sessions/{session_id} every 2 seconds, up to 5 times, until ready is true. Return to each player the relay IP, the server port for the host or the client port for the others, the session authorization_token, and that player's own authorization_token from session_users, matched by IP. Never return the relay profile token.
No backend yet? Ask your agent to create a test session for your players' public IPs: it returns the same values. Delete it when you're done, since sessions bill while they're open.
Here's our video tutorial of Edgegap's relays with Mirror in Unity:
5. Connect the host and players
In your game, set the values from step 4 on the EdgegapKcpTransport, then start Mirror:
Relay address: the relay
ip.Session ID: the session
authorization_token.User ID: this player's own
authorization_token.Relay port: the server port for the host, the client port for everyone else.
The sample sets them in one call, ChangeValue, then the host calls StartHost() and the others call StartClient().
In my Mirror project, after my backend returns the relay values, set them on the EdgegapKcpTransport (relay address, session ID from the session authorization_token, user ID from this player's authorization_token, relay port from the server port if I host or the client port otherwise), then call StartHost() or StartClient(). Show me where the transport fields are set and return the complete file.
The host and the clients all connect out to the relay, so nobody opens a port and no player sees another player's IP address.
6. Group players and add late joiners
A relay session is created for players you've already grouped, so the grouping happens before step 4: in your own lobby, Steam lobbies, Epic Online Services lobbies or Unity's Lobby service. Whatever groups them calls your backend with their public IPs.
A player joining after the session started? Authorize their IP on the existing session from your backend, then send them the same values. For a test, ask your agent:
Authorize this public IP on my Edgegap relay session {session_id}.
When the match ends, delete the session from your backend: DELETE https://api.edgegap.com/v1/relays/sessions/{session_id}. Players lose the relay connection and billing for that session stops.
7. Test with two players
Clone the Mirror relay sample and open the folder in Unity Hub.
For this local test only, paste your relay profile token in RelayProfileToken on the HelloWorldManager component of the NetworkManager game object. Remove it before you ship: in a build, players could read it.
Run two instances, with Unity's Multiplayer Play Mode or the Editor plus a build. Start a host in the first, then join from the second.
Both players play the same match through the relay. Delete the test session when you're done.
Prefer an authoritative server? No host advantage, and the match survives the host leaving: see Mirror Networking, and add matchmaking with the Unity Matchmaking SDK.
Stuck? Ask our team and other studios on the Edgegap Discord.
Frequently Asked Questions
Common questions about adding Edgegap's relays to a peer-to-peer Unity multiplayer game.
What is a relay in multiplayer games?
A relay forwards traffic between players when they can't connect directly, for example behind strict NAT or a firewall. One player's game hosts the match and the relay only passes messages, so nobody opens ports and players never see each other's IP address.
Should I use a relay or a dedicated server?
A relay keeps your peer-to-peer netcode as it is, but the host owns the game state: the host can cheat, plays with no latency, and the match ends when the host leaves unless your game migrates the host. An authoritative game server on Edgegap removes those limits. Use a relay when your game is already built host-client and moving to a server isn't an option.
Do Edgegap's relays work with Netcode for GameObjects and Fish-Networking?
Yes. Edgegap provides relay transports for Mirror, Netcode for GameObjects and Fish-Networking. Other netcodes can follow the relay implementation manual: the relay carries unreliable UDP, and your netcode handles reliability.
Can I put the relay token in my game client?
No. Anyone holding it can create sessions on your account. Keep it in your lobby, matchmaker or backend, and send each player only the relay address, their port, the session token and their own token.
How are relay sessions billed?
A session bills while it's open, and billing stops when you delete it. Delete each session when its match ends, and delete test sessions when you're done.

Clients
Learn more from clients who integrated Edgegap
31 case studies are available from studios that moved to Edgegap from another platform.

A Flawless Global Launch for Rivals of Aether 2
Aether Studios
Learn how Aether Studios quickly added Edgegap and delivered flawless launch & post-launch to their community.
Case Study

Overcome Latency Introduced by VR’s use of WiFi in Competitive Multiplayer
Halfbrick Studios
Discover how Halfbrick successfully launched & maintains a multiplayer-focused Early Access on META Quest's VR platform.
Case Study

MENA’s Social App Adds Online Games
WOLF
Learn how the highly popular MENA-region social app added matchmaking & multiplayer games orchestration easily to WOLF Qanawat.
Case Study

Hybrid Orchestration Keeps Kickoff Tactics Ready for Any Traffic
Birch Games
How hybrid orchestration helped Birch Games handle traffic, pairing egress-free Fleets with the regionless cloud.
Case Study

7 Days Blood Moons
The Fun Pimps & iLLOGIKA
Learn how Illogika dramatically reduced server costs & ensured the online experience the 7 Days to Die franchise expects.
Case Study

Authentic Online Warfare Requires the Ultimate Orchestration
Highwire Games
Learn how Highwire's need for performance required orchestration only Edgegap can deliver.
Case Study

22,000 Reviews, 4.8 Stars, and Infrastructure That Scaled Automatically
Sinn Studios
How a simple, Slack-supported integration got Sinn Studio's hit VR title online fast and keeps it there.
Case Study

Dynamic Server Orchestration
Under NDA - AAA Studio
Discover how one the world's biggest AAA studio improved its peer-to-peer multiplayer experience through edge computing.
Case Study

Near Zero Latency for AAA Fighting Game
AAA Studio - Under NDA
How an unannounced project delivered the lowest lag possible and improved fairness in its 1v1 game.
Case Study

Play Gods with Multiplayer Physics
Squido Studio
Learn how Squido uses Edgegap's highligh optimized game servers to deliver mind-bending & chaotic VR gameplay.
Case Study

A Fully Managed Solutions that Saves Time for Indies Multiplayer VR Horror
Dirty Pearl Studios
Discover how Dirty Pearl Studios saved development time thanks to Edgegap’s easy integration and automated orchestration alongside its Nakama integration.
Case Study

Instant Global Server Deployment for Collaborative XR Medical Education
AlensiaXR
How AlensiaXR uses Edgegap to deliver low-latency, always-available shared anatomy sessions to medical students worldwide.
Case Study

The Lightkeepers: A VR Social Co-op Game with Dedicated Servers
Spectral Games
How Spectral Games used Edgegap Matchmaking and Server Browser to launch dedicated servers for its VR social lobby, with no prior server experience.
Case Study

Fast & reliable deployments worldwide for PvPvE challenger Gravebound
Crater Studios
How Edgegap’s orchestration and matchmaking helped Crater Studios dramatically helped a small them focus on gameplay instead of infrastructure.
Case Study

Rapid Scaling of Web Metaverse
Hiber
Learn how Hiber eliminated the guesswork out of its server capacity planning with Edgegap.
Case Study

High Hardware Requirements & Custom Game Server Pools
Alderon Games
Learn how Alderon Games instantly leverages a custom pool of game servers across multiple providers worldwide for its popular MMO.
Case Study

Easy Integration for Indie Devs
WhaleFood Games
Read how WhaleFood Games "kicked out" its netcode issues with Edgegap.
Case Study

Cutting-edge tech that powers South-East Asia’s first-ever eSports title.
Anantarupa Studios
Learn how Edgegap transformed South-East Asia’s gaming landscape streamlining complex infrastructure and cutting-edge tech with one seamless solution.
Case Study

One Strike. Global Reach.
Triple Hill Interactive
How Triple Hill Interactive leverages Edgegap's orchestration to deliver low latency and improve fairness in a genre where every millisecond counts.
Case Study

Fast-paced Team Battle Royale... with Gun-totting Animal Plushes!
SANDYFLOOR
Discover how a Korea-based Indie Studio launched it multiplayer worldwide.
Case Study

Mobile Horse Racing Goes Global with Instant, Cost-Efficient Servers
Mirai Labs
How Mirai Labs powers Pegaxy Blaze's worldwide multiplayer races with just-in-time server deployment and fractional vCPU to keep cost per player low.
Case Study

Server Management & Distribution
Matrioshka Games
Read how Matrioshka Games were able to ship a Battle Royale in early access with limited ressources.
Case Study

At my Signal, Unleash Hell!
TyGames
Discover how Indie studio TyGames immerses players in third-person gladiatorial combat multiplayer.
Case Study

Instant Worldwide Orchestration
Soliton Interactive
Discover how Soliton Interactive did the impossible… Ship it's first playable as multiplayer!
Case Study

Competitive play with server-side physics ensures ideal sub-50 ms latency
NS7
Discover why solely Edgegap could enable an indie studio to deliver on its vision for a AAA-quality F2P sports gameplay through server-side physics and authority.
Case Study

Regional Deployments for iGaming
X1 Contra 1
X1 Contra 1 delivers real-time PvP casual games to its Brazilian player base through cost-effective hosting & regional deployments, ensuring data and legal compliance.
Case Study

Pay Only When Players Play: Affordable Multiplayer Infrastructure
Meltdown Interactive
How Edgegap helped indie developer Meltdown Interactive Media solve cost-effective scaling and matchmaking without the complexity, so they could focus on building the game.
Case Study

One Edgegap platform, three very different networking profiles
Warped Games
How Warped Games runs a social hub, real-time co-op, and turn-based co-op, all on the same Edgegap deployment API and the same container pipeline.
Case Study

Pool Live Tour Max
RETA Games
Case Study

Korea’s Web3 POP Extraction Shooter Goes Global, Instantly
NDUS Entertainment
How XOCIETY easily added Edgegap orchestration & integrated custom matchmaking working alongside Edgegap Ping Beacons to optimize latency.
Case Study

Multiplayer in Every Dimension
Arcadia.tv
Discover how Arcadia.tv uses Edgegap's edge network to deliver an innovative, team and location-based athletic VR sport.
Case Study

F2P Mobile Fighter Cuts Infrastructure Costs With Just-in-Time Servers
Game Changers Worldwide
How Game Changer Worldwide hosted Rumble Rush's real-time 3v3 PvP globally on mobile.
Case Study
Key reasons why they chose Edgegap
Discover the impact of Edgegap's automated game server orchestration for a flawless multiplayer experience.









