> For the complete documentation index, see [llms.txt](https://docs.edgegap.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.edgegap.com/docs/sample-projects/unity-netcodes/playfab-spaceedge.md).

# PlayFab SpaceEdge

A Unity space shooter where PlayFab Matchmaking pairs players and two Azure Functions start an Edgegap dedicated server near them for every match.

Explore how to keep **PlayFab Matchmaking** and run every match on its own **Edgegap** dedicated server with the [SpaceEdge PlayFab sample](https://github.com/edgegap/backend-game-sample-unity-playfab-matchmaker-fishnet-spaceedge), a small Unity space shooter on FishNet.

Players sign in to PlayFab and press **Start Game**. When PlayFab matches them, an Azure Function starts an Edgegap server near them, and a second one hands each player the address and a join token. The server admits only the matched players, and stops itself when they leave.

This sample shows:

* **Unity 2021.3.45f2** project on **FishNet 3.11.14** (Tugboat, UDP 7770), built as a Linux dedicated server with the [Edgegap Unity plugin](https://github.com/edgegap/buildtool-unity-plugin),
* **PlayFab Matchmaking** with server allocation off: PlayFab forms the match, Edgegap hosts it,
* **two Azure Functions** (Node.js 22, no SDK): one deploys the server on `match_found`, the other receives Edgegap's ready webhook and writes the address to each player's read-only data,
* **join tokens**: the server admits only the players PlayFab matched, without holding any PlayFab secret,
* **server self-stop**: the server stops its own deployment when nobody joins, or after everyone has left.

{% hint style="info" %}
Verified end to end on Edgegap on 21 October 2026 with Windows clients and a PlayFab queue of 2: the address reached both players about 8 seconds after the function call. Join tokens and the plugin build came later, and were tested with unit tests and a local server container.
{% endhint %}

{% hint style="success" %}
[Deploy from PlayFab](https://docs.edgegap.com/docs/tools-and-integrations/playfab-bridge.md) explains each part, for adding Edgegap to your own PlayFab game.
{% endhint %}

## ✔️ Preparation

{% hint style="info" %}
This sample was developed and tested on Unity `2021.3.45f2` - please use the same version.
{% endhint %}

Before you get started, make sure to [create a free account with Edgegap](https://app.edgegap.com/auth/register) (no credit card required). You can [invite your team members afterwards](https://app.edgegap.com/user-settings?tab=organizations), even if they don't have an Edgegap account yet.

**Configure a few essentials on your development machine:**

<details>

<summary>Install Unity Linux Build Support Modules</summary>

* Use Unity Hub to select tab **Installs**, access **Settings** and **Add Modules** for each Unity version you intend to use with Edgegap platform:

<figure><img src="https://3027732442-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsR0dHSFv9ymoC0DO5G8J%2Fuploads%2FylRG4r8orenZrw5ijjpJ%2Fimage.png?alt=media&amp;token=fb981825-8a15-4c07-9180-0f79a6a77a91" alt=""><figcaption></figcaption></figure>

* Scroll down to select and install the following Unity modules:
  * **Linux Build Support (IL2CPP),**
    * **Linux Build Support (Mono),**
    * **Linux Dedicated Server Build Support**

<figure><img src="https://3027732442-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsR0dHSFv9ymoC0DO5G8J%2Fuploads%2FuXtyqoLhBOk8CZJ4WdzA%2Fimage.png?alt=media&amp;token=19e956ed-a731-420d-b911-130c334794fc" alt=""><figcaption></figcaption></figure>

</details>

<details>

<summary><a href="https://www.docker.com/products/docker-desktop/">Install Docker Desktop (or Docker CLI)</a></summary>

* [Install Docker Desktop from the official source](https://www.docker.com/products/docker-desktop/) (no account required).
* Restart your computer after completing the installation.

</details>

* a [PlayFab](https://developer.playfab.com) title, its Title ID and a secret key,
* an Azure subscription and the [Azure CLI](https://learn.microsoft.com/cli/azure/install-azure-cli),
* an Edgegap API token from [Dashboard → User Settings → Tokens](https://app.edgegap.com/user-settings?tab=tokens). It goes only in the Function App's settings, never in the game.

## ⚡ Run the Sample

### 1. Game Server

{% hint style="info" %}
Find a more detailed guide for this step in [Unity](https://docs.edgegap.com/unity.md) getting started guide.
{% endhint %}

Open `SpaceEdge_project` in Unity, then **Tools → Edgegap Server Hosting**:

1. **Sign in with Edgegap**, then **Build server**.
2. **Containerize with Docker**: image name `playfab-fishnet`, image tag empty (the plugin uses the current UTC time).
3. **Upload to Edgegap**: application `playfab-fishnet`, then **Upload image and Create app version**. In the version form that opens, set one port named `gameport`, 7770, UDP, and 0.5 vCPU / 1 GB. Keep the proposed version name: the Azure Functions need it.

{% hint style="info" %}
No environment variables or secret needed for server, functions pass the deployment match details.
{% endhint %}

### 2. PlayFab Title

1. Create a matchmaking queue `edgegap-fishnet`, match size 2-2, with **Enable server allocation** off.
2. In **Title settings → API Features**, untick **Disable player creation using Client/LoginWithCustomId**.
3. Create a secret key in **Title settings → Secret Keys**.

### 3. Azure Functions

Deploy the sample's `azure-functions` folder to a Flex Consumption Function App on Node.js 22, and set its app settings, as in [Deploy from PlayFab](https://docs.edgegap.com/docs/tools-and-integrations/playfab-bridge.md). Use your application `playfab-fishnet` and the version name from step 1. Then register `StartEdgegapDeployment` in PlayFab and add the rule on `playfab.matchmaking.match_found`.

### 4. Play a Match

1. Open the scene `Assets/SpaceEdge/Scenes/MainMenu`, and on the `PlayfabRestApiService` object set your **Title Id**. The queue name is already `edgegap-fishnet`.
2. Build the Windows test client (Mono, no Windows IL2CPP module needed) and run it twice, as two PlayFab players:

```bash
"<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
```

3. Press **Start Game** in both. Once PlayFab matches them, a deployment tagged with the start of the match ID appears in the [Edgegap dashboard](https://app.edgegap.com/deployment-management/deployments/list), and both clients connect a few seconds later.
4. Quit both: the server stops itself within a minute.

{% hint style="info" %}
The free tier runs one deployment at a time: stop other deployments before you test.
{% endhint %}

## 🔧 Known Limits

* **2 players per match.** Only queues of 2 were tested. For larger matches, raise the queue's match size and test again.
* **Windows clients only were tested.** The client code uses only `UnityWebRequest` and `JsonUtility`, so it could run in WebGL, but a web build would also need a WebSocket transport and port.
