Discover how Edgegap works

Discover how Edgegap works

PlayFab

SpaceEdge

Deploy to Edgegap

Published

Published

Published

Last reviewed for accuracy

Last reviewed for accuracy

Last reviewed for accuracy

SpaceEdge: Run a PlayFab Matchmaking sample on Edgegap dedicated servers, in Unity

SpaceEdge: Run a PlayFab Matchmaking sample on Edgegap dedicated servers, in Unity

SpaceEdge is a small Unity space shooter that shows PlayFab Matchmaking and Edgegap working together, end to end: PlayFab signs players in and matches them, and every match gets its own Edgegap dedicated game server.

PlayFab keeps doing what it does: accounts, login and matchmaking queues. When it finds a match, an Azure Function starts an Edgegap server near the matched players, and a second one tells each player where to connect.

No secret ships in the game: the client holds only your PlayFab title ID, and the game server holds no PlayFab or Edgegap credentials and admits only the matched players. The server stops itself when the players leave.

Edgegap's network spans 615+ Edge Cloud locations (learn more). Each server is deployed to the best available location for its players and billed only while the match runs.

Platforms: Windows desktop client (tested). A Linux dedicated server, built with the Edgegap Unity plugin. The client code could run in WebGL, but WebGL hasn’t been tested.

How it works

  1. The player signs in to PlayFab and presses Start Game: the client creates a matchmaking ticket in a PlayFab queue.

  2. PlayFab matches two players and fires playfab.matchmaking.match_found. A rule on that event runs the Azure Function StartEdgegapDeployment.

  3. The function looks up each player’s location and asks Edgegap for a deployment near them, tagged with the start of the match ID. It returns in about a second.

  4. When the server is up, Edgegap calls the second function, EdgegapDeploymentReady. It checks the deployment with the Edgegap API, then writes the server’s host and port, and a join token, to each player’s read-only PlayFab data.

  5. Both clients read the address, connect over UDP with their join token and play. The server turns away anyone else. When they leave, the server stops its own deployment.

What's in the repo:

Path

What it does

azure-functions/

The two Azure Functions (Node.js 22, no PlayFab or Edgegap SDK).

.../PlayfabTest/PlayFabMatchmakingClient.cs

Client: login, ticket, wait for the match, wait for the server, connect. UnityWebRequest and JsonUtility only, no PlayFab SDK.

.../Edgegap/EdgegapServer.cs

Server: starts the game server in server builds and stops the Edgegap deployment when the match is over. Adds itself at runtime, no scene setup.

.../Editor/EdgegapPluginBuild.cs

Command-line builds: the Edgegap plugin’s server build, and the Windows test client.

.../Edgegap/JoinTokenAuthenticator.cs

Admits only the matched players: checks the join token each client sends.

No credit card required. Free tier includes the resources to deploy a real game server.

No credit card required. Free tier includes the resources to deploy a real game server.

Step-by-Step Guide

Run the Sample

1. Before you start

2. Put the game server on Edgegap

Open SpaceEdge_project in Unity, then Tools → Edgegap Server Hosting, and sign in with Edgegap.

Build server, then Containerize with Docker: image name playfab-fishnet, image tag empty (the plugin uses the current UTC time).

Upload to Edgegap: application playfab-fishnet, then Upload image and Create app version. The plugin pushes the image and opens the version form:

Without the Editor, the same server build runs from the command line:

"<Unity>" -batchmode -projectPath SpaceEdge_project -executeMethod EdgegapPluginBuild.BuildServer -logFile build-server.log

For later builds, Rebuild from Source builds, containerizes and pushes in one click.

In the version form:

  • Keep the image and the version name the plugin proposes (the image tag). The Azure Functions need that name. If the form asks for registry credentials, use the username and token from the Container Registry page.

  • One port: name gameport, 7770, UDP. The functions look the port up by that name.

  • 0.5 vCPU and 1 GB.

  • A max duration of 60 minutes. The server also stops itself.

The version needs no environment variables and no secrets: the functions pass the match details and join tokens to each deployment.

3. Set up your PlayFab title

  1. Matchmaking queue (Multiplayer → Matchmaking → New queue): name edgegap-fishnet, match size 2-2, Enable server allocation off, since Edgegap hosts the servers. No rules are needed to match any two players.

  2. Let clients create players (gear icon → Title settings → API Features): untick Disable player creation using Client/LoginWithCustomId. New titles have it ticked, and logins fail with PlayerCreationDisabled.

  3. Note your Title ID, and create a Secret Key (Title settings → Secret Keys) for the Azure Functions.

4. Deploy the Azure Functions

Create a resource group, a storage account and a Flex Consumption Function App on Node.js 22. PlayFab recommends a US West region:

az group create -n rg-edgegap-playfab -l westus2

az storage account create -n <storageaccount> -g rg-edgegap-playfab -l westus2 --sku Standard_LRS

az functionapp create -g rg-edgegap-playfab -n <function-app> --storage-account <storageaccount> --flexconsumption-location westus2 --runtime node --runtime-version 22

In azure-functions, run npm ci --omit=dev, zip host.json, package.json, src/ and node_modules/ into bridge.zip, then deploy it:

az functionapp deployment source config-zip -g rg-edgegap-playfab -n <function-app> --src bridge.zip

Add the app settings (Function App → Settings → Environment variables):

  • PLAYFAB_TITLE_ID and PLAYFAB_SECRET_KEY: from step 3.

  • EDGEGAP_API_TOKEN: your Edgegap token, without the token prefix.

  • EDGEGAP_APP_NAME / EDGEGAP_APP_VERSION: playfab-fishnet / the version name from step 2. EDGEGAP_PORT_NAME is optional and defaults to gameport.

  • EDGEGAP_READY_WEBHOOK_URL: https://<function-app>.azurewebsites.net/api/EdgegapDeploymentReady?code=<function key>.

  • Optional: EDGEGAP_QUEUES to give Edgegap servers to some queues only, and FALLBACK_LATITUDE / FALLBACK_LONGITUDE for players PlayFab can't locate.

Get each function's key with az functionapp function keys list -g rg-edgegap-playfab -n <function-app> --function-name <name>. Function keys are secrets: don't commit or share URLs that contain them.

Then, in PlayFab:

  1. Automation → CloudScript → Functions → Register Function: name StartEdgegapDeployment, with its URL and function key.

  2. Automation → Rules → New Rule: event type playfab.matchmaking.match_found, action Execute Azure Function → StartEdgegapDeployment.

Don't register EdgegapDeploymentReady: Edgegap calls it, not PlayFab.

5. Play a match

  1. Open SpaceEdge_project and the scene Assets/SpaceEdge/Scenes/MainMenu.

  2. On the PlayfabRestApiService object (component PlayFabMatchmakingClient), set Title Id. Queue Name is already edgegap-fishnet.

  3. Make sure no other deployment is running: the free tier runs one at a time.

You need two players. Build a Windows client (Mono, so the Windows IL2CPP module isn’t needed) and run it twice, each with its own PlayFab player:

"<Unity>" -batchmode -projectPath SpaceEdge_project -executeMethod EdgegapPluginBuild.BuildClient -logFile build-client.log

SpaceEdge_project/Builds/Client/win64/Game.exe -playfabCustomId player-a

SpaceEdge_project/Builds/Client/win64/Game.exe -playfabCustomId player-b

Press Start Game in both. Once PlayFab matches them, a deployment tagged with the start of the match ID appears in the Edgegap dashboard, and both clients connect to it a few seconds later. Quit both: the server stops on its own within a minute.

Other options: -playfabTitleId <id>, -playfabQueue <name>, and -autoMatch to queue right after login. For headless test clients, add -batchmode -nographics -client.

6. Add PlayFab Matchmaking to your own game

The sample is a working reference: your coding agent can copy its tested files instead of writing them from scratch. Four changes make a game run on Edgegap with PlayFab Matchmaking:

  1. PlayFab only matches. Turn server allocation off on your queue, so PlayFab forms the match and Edgegap hosts it. No GSDK and no PlayFab builds.

  2. Two Azure Functions connect them. One deploys a server near the players on match_found; the other receives Edgegap’s ready webhook and writes the address and a join token to each player’s read-only data (azure-functions/, usable as is with any engine).

  3. The server runs headless and stops itself. It listens on a fixed port, holds no secret, admits only the matched players, and stops its deployment when nobody joins or everyone leaves (EdgegapServer.cs). The sample's netcode is FishNet; for another netcode, replace the part that starts the server and counts players.

  4. The client waits for its server. After Matched, it reads EdgegapServer from its read-only data and connects with its join token to host:port (PlayFabMatchmakingClient.cs, with one netcode-specific connect call).

With your agent:

"Load the edgegap skill, then edgegap-playfab and the skill for my netcode. Using github.com/edgegap/backend-game-sample-unity-playfab-matchmaker-fishnet-spaceedge as the reference, add a headless server mode that stops itself to my game, deploy the two Azure Functions to my subscription, and wire my client to queue in PlayFab and connect to the address in its read-only data."

For each step in detail, by hand, see the PlayFab integration guide.

Known limits

  • 2 players per match. The queue is 2-2, and only queues of 2 were tested. For larger matches, raise the queue's match size and test again.

  • Windows clients only. macOS and Linux client builds weren’t tested.

  • WebGL not tested. The client code avoids threads and the PlayFab SDK, so it could run in a browser, but a web build would also need a WebSocket port with TLS Upgrade.

What was tested

Tested end to end on Edgegap on 21 October 2026, with Unity 2021.3.45f2, Node.js 22 on Azure Functions (Flex Consumption) and a PlayFab queue of 2:

  • Two clients signed in and were matched by PlayFab.

  • The rule ran StartEdgegapDeployment, one server started near them, and the address reached both players about 8 seconds after the function call.

  • Both connected to the same server and played.

  • The server stopped itself after the players quit, and 2 minutes after start when nobody joined.

Join tokens and the build with the Edgegap Unity plugin came after this run. They were tested on 29 October 2026 with unit tests and a local server container: matched players got in, anyone else was turned away, and a crashed player could rejoin. Not tested: WebGL clients, queues larger than 2, latency-based queue rules.

Frequently Asked Questions

Questions about running the SpaceEdge sample with PlayFab and Edgegap.

Is there a PlayFab Matchmaking sample for Unity with dedicated servers?

Yes. SpaceEdge is a Unity space shooter where PlayFab Matchmaking pairs two players and two Azure Functions start an Edgegap dedicated server near them for the match. It was tested end to end in October 2026.

Why does the sample use Azure Functions instead of CloudScript?

Microsoft calls JavaScript CloudScript “classic” and points new work to CloudScript using Azure Functions. The functions also let the deploy call return in about a second and receive Edgegap’s webhook when the server is ready.

Does the game server need the PlayFab secret key?

No. The secret key and the Edgegap token stay in the Function App’s settings. The client holds only the title ID, and the server reads nothing from PlayFab. It checks players with per-match join tokens that the functions compute.

How do I test two PlayFab players on one machine?

Run two client builds with different custom IDs, for example -playfabCustomId player-a and -playfabCustomId player-b. Copies on one machine share PlayerPrefs, so without it both sign in as the same player.

Clients

Learn more from clients who integrated Edgegap

31 case studies are available from studios that moved to Edgegap from another platform.

Key reasons why they chose Edgegap

Discover the impact of Edgegap's automated game server orchestration for a flawless multiplayer experience.

Cost

Pricing

Pricing

Optimize costs and performance with hybrid orchestration

Optimize costs and performance with hybrid orchestration

Optimize costs and performance with hybrid orchestration

Edge Cloud

On-Demand

$0.00115

/ vCPU

/ MINUTE

Billed by the Minute, Only on Usage

Pay only when players play. 0 active servers = $0

Deploy game servers worldwide, per instance, to all 615+ edge cloud locations. Zero commitment.

Simply add a credit card.

Edge Cloud

On-Demand

$0.00115

/ vCPU

/ MINUTE

Billed by the Minute, Only on Usage

Pay only when players play. 0 active servers = $0

Deploy game servers worldwide, per instance, to all 615+ edge cloud locations. Zero commitment.

Simply add a credit card.

Edge Cloud

On-Demand

$0.00115

/ vCPU

/ MINUTE

Billed by the Minute, Only on Usage

Pay only when players play. 0 active servers = $0

Deploy game servers worldwide, per instance, to all 615+ edge cloud locations. Zero commitment.

Simply add a credit card.

Private Fleet (Bare Metal)

Reserved Capacity

$0.0261

/ vCPU

/ HOUR

Billed Monthly, Always On

$280 per host/month (12 mo rate), or $350 monthly

Optimize the cost effectiveness of your game server with egress-free hosting of Private Fleets.

Persistent, available 24/7, exclusive to your studio.

Private Fleet (Bare Metal)

Reserved Capacity

$0.0261

/ vCPU

/ HOUR

Billed Monthly, Always On

$280 per host/month (12 mo rate), or $350 monthly

Optimize the cost effectiveness of your game server with egress-free hosting of Private Fleets.

Persistent, available 24/7, exclusive to your studio.

Private Fleet (Bare Metal)

Reserved Capacity

$0.0261

/ vCPU

/ HOUR

Billed Monthly, Always On

$280 per host/month (12 mo rate), or $350 monthly

Optimize the cost effectiveness of your game server with egress-free hosting of Private Fleets.

Persistent, available 24/7, exclusive to your studio.

Your bill varies per rate and usage; which can vary per game type, player count, & more.

Your bill varies per rate and usage; which can vary per game type, player count, & more.

Model your usage with our estimate calculator ->

Model your usage with our estimate calculator ->

Edgegap's features & price: detailed comparison between Edge Cloud & Private Fleets

Edgegap's features & price: detailed comparison between Edge Cloud & Private Fleets

COMPARE

Free Trial

Edge Cloud

Private Fleets

FEATURES

Analytics & Monitoring

Billing Alarms

Click to Expand

28 more rows

Unlocks

Capabilities are unlocked when a credit card is added to the account.

COMPARE

Free Trial

Edge Cloud

Private Fleets

FEATURES

Analytics & Monitoring

Billing Alarms

Click to Expand

28 more rows

Unlocks

Capabilities are unlocked when a credit card is added to the account.

COMPARE

Free Trial

Edge Cloud

Private Fleets

FEATURES

Analytics & Monitoring

Billing Alarms

Click to Expand

28 more rows

Unlocks

Capabilities are unlocked when a credit card is added to the account.