> 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/unreal-engine/lyra-sample.md).

# Lyra Sample

Host Epic's Lyra Starter Game (Unreal Engine 5.8) on Edgegap dedicated servers, with Epic Online Services sessions and Edgegap matchmaking.

[Lyra Starter Game](https://dev.epicgames.com/documentation/en-us/unreal-engine/lyra-sample-game-in-unreal-engine) is Epic's multiplayer sample for Unreal Engine 5. This sample hosts Lyra on Edgegap dedicated servers and keeps everything Lyra does with Epic Online Services (EOS): Epic account login, friends, presence and the session browser.

{% hint style="success" %}
See our [Lyra sample repository](https://github.com/edgegap/game-sample-unreal-engine-lyra) with the plugin, config, `Dockerfile` and matchmaker config.
{% endhint %}

{% hint style="info" %}
See [Unreal Engine - Getting Started](https://docs.edgegap.com/unreal-engine.md) to **learn how to build and customize servers**.
{% endhint %}

This sample shows:

* **Start a Game** (Online) asks the Edgegap [matchmaker](https://docs.edgegap.com/learn/matchmaking.md) for a server near the players, measured with [Ping Beacons](https://docs.edgegap.com/learn/orchestration/ping-beacons.md), instead of making a player the listen server,
* every Edgegap server registers an **EOS session**, so Lyra's **Browse** and **Quick Play** find it and other players join through EOS,
* players sign in with their **Epic account**, the dedicated server uses its own EOS client and never logs in,
* servers started by the matchmaker stop their own deployment 15 seconds after the last player leaves, or after 5 minutes if nobody joins, so idle servers don't keep billing.

The repository holds only Edgegap's part: a C++ plugin (no content assets), config blocks, a `Dockerfile` and a matchmaker config. You add them to your own copy of Lyra, which comes from Epic under the Unreal Engine EULA.

## ✔️ Preparation

Before we start, you will need:

* [Unreal Engine 5.8](https://www.unrealengine.com/en-US/download) - download using Epic Games Launcher,
* [Lyra Starter Game for 5.8](https://www.fab.com/listings/93faede1-4434-47c0-85f1-bf27c0820ad0) from Fab, then **Create Project** from your Fab Library,
* Docker Desktop, and a GitHub account [linked to your Epic account](https://www.unrealengine.com/en-US/ue-on-github) to pull Epic's engine image `ghcr.io/epicgames/unreal-engine:dev-slim-5.8.4`,
* an Epic Online Services product in the [Epic Developer Portal](https://dev.epicgames.com/portal),
* a free [Edgegap account](https://app.edgegap.com/auth/register).

{% hint style="info" %}
The Unreal Engine installed from the Epic Games Launcher can't build Server targets. This sample builds the Linux server inside Epic's engine image instead, so **no engine source build is needed**.
{% endhint %}

## ⚙️ Add Edgegap to Lyra

☑️ Copy `Plugins/EdgegapIntegration` from the repository into your project's `Plugins` folder.

☑️ Enable `OnlineSubsystemEOS` and `EdgegapIntegration` in your `.uproject` plugins list.

☑️ Append `Config/DefaultEngine.Edgegap.ini` to your `Config/DefaultEngine.ini`, and `Config/DefaultGame.Edgegap.ini` to your `Config/DefaultGame.ini`.

☑️ In `Source/LyraServer.Target.cs`, apply `bUseChecksInShipping = true;` only when `BuildEnvironment == TargetBuildEnvironment.Unique`, so Epic's engine image can build the server.

✅ You may now proceed to the next step.

{% hint style="info" %}
EOS settings go in `DefaultEngine.ini`, not Lyra's `Config/Custom/EOS` folder: that folder is only packaged for targets which an installed engine can't build.
{% endhint %}

## 🔑 Epic Online Services

☑️ In your product's **Client Policies**, create a **Peer2Peer** policy for players, and a **Custom** policy for servers with **Sessions** enabled (every action) and **User required** turned off.

☑️ Create two **Clients**, one for each policy, for example *Lyra Client* and *Lyra Server*.

☑️ In **Epic Account Services**, accept the terms, create an application, enable **Online Presence** and **Friends**, and link *Lyra Client*.

☑️ Put your product, sandbox and deployment IDs and the *Lyra Client* ID in the `LyraEdgegap` artifact in `DefaultEngine.ini`.

☑️ Copy `Config/UserEngine.ini.example` to `Config/UserEngine.ini`, fill in the *Lyra Client* secret and an encryption key, and keep this file out of version control.

{% hint style="warning" %}
**Never put the** ***Lyra Server*** **secret in a file or game client.** Your dedicated server reads it from environment variables on your Edgegap app version.
{% endhint %}

## ⚡ Deploy and Connect

### 1. Package and Upload the Server

☑️ Package the Linux dedicated server inside Epic's engine image, following the repository README. The first build takes about 40 minutes, later builds reuse the cache volumes.

☑️ Build your image with the included `Dockerfile`, setting `PROJECT` to your `.uproject` name (`LyraStarterGame` when created from Fab), and push it to your registry:

{% code collapsedlinecount="10" %}

```shell
docker build --platform linux/amd64 --build-arg PROJECT=LyraStarterGame -t <REGISTRY>/<IMAGE>:<TAG> .
docker push <REGISTRY>/<IMAGE>:<TAG>
```

{% endcode %}

☑️ [Create an app version](https://app.edgegap.com/application-management/applications/list) with your image, port `7777` **UDP** named `gameport`, 1.5 vCPU and 3 GB of memory.

☑️ Add environment variables `EOS_SERVER_CLIENT_ID` and `EOS_SERVER_CLIENT_SECRET` (secret) with your *Lyra Server* client.

### 2. Create a Matchmaker

☑️ Set your app version in the repository's `matchmaker-config.json`, with profiles `controlpoint`, `elimination` and `topdown` for Lyra's playlists.

☑️ [Create a matchmaker](https://app.edgegap.com/matchmaker-management-v2/matchmakers/list) with this configuration and wait until it's ready.

☑️ Copy the matchmaker's **URL** and **Auth Token** into `Config/UserEngine.ini`.

### 3. Play

☑️ Start Lyra, press any key and sign in with your Epic account.

☑️ Open **Play Lyra / Start a Game**, keep Network **Online**, and choose **Control Point**.

☑️ Within seconds, your matchmaker starts a server near you and Lyra joins it. Alone, you'll get your own server after 10 seconds.

🙌 Congratulations, you're playing Lyra on Edgegap with Epic Online Services!

{% hint style="info" %}
A fresh Lyra server first loads an empty map and then travels to the match map, which disconnects anyone already connected. The plugin reconnects automatically, so you may see the loading screen twice.
{% endhint %}

## 🔧 Troubleshooting

<details>

<summary>Players are disconnected with "Host closed the connection" right after joining.</summary>

* The server dropped early joiners when traveling to the match map, the client rejoins up to 5 times within 60 seconds,
* if it still fails, inspect your [deployment](https://docs.edgegap.com/learn/orchestration/deployments.md) logs.

</details>

<details>

<summary>My deployment fails with "Unable to pull image from registry".</summary>

* Add your Container Registry credentials to your app version.

</details>

<details>

<summary>My server logs show an Epic login device code and the match never starts.</summary>

* Make sure the `EdgegapIntegration` plugin is enabled: it turns off Epic account login on dedicated servers.

</details>

<details>

<summary>The server build fails with "Project contains multiple Server targets".</summary>

* Your `DefaultEngine.ini` is missing `DefaultServerTarget=LyraServer` from the appended config block.

</details>

{% hint style="success" %}
Add in-game voice chat with Epic Online Services, see [EOS Voice Chat](https://docs.edgegap.com/docs/tools-and-integrations/eos-voice-chat.md).
{% endhint %}
