# Integrating with Lyra Game

The [**Lyra Sample Game**](https://docs.unrealengine.com/5.0/en-US/lyra-sample-game-in-unreal-engine/) released by Epic Games proved to be popular among indie developers. This section will be helpful for those who want to integrate **Kronos Matchmaking** into the Lyra project.

## Sessions in Lyra

All online features in Lyra are implemented in the [**Common User Plugin**](https://dev.epicgames.com/documentation/en-us/unreal-engine/common-user-plugin-in-unreal-engine-for-lyra-sample-game). This plugin was designed to be a base for other projects to use as a base when customizing Lyra. Its two main parts are the `CommonUserSubsystem` which handles user authentication, and the `CommonSessionSubsystem` which handles basic session operations such as hosting and joining online games.

Unfortunately the [**Common User Plugin**](https://dev.epicgames.com/documentation/en-us/unreal-engine/common-user-plugin-in-unreal-engine-for-lyra-sample-game) tries to do things that Kronos also handles automatically. This results in kind of a conflicting situation where both plugins are trying to do the same thing on their own way. The best option would be to disable the Common User plugin entirely, however this isn't really an option due to the fact that it is integrated into the `LyraGameMode` and `LyraGameInstance` classes on a C++ level.

## Fixing Code Issues

To get everything working we will need to make some small changes to the C++ code directly.

### 1. Generating C++ Project Files

1. Go to your Lyra project folder.
2. Right click on the `.uproject` file and select the "Generate Visual Studio Project Files" option. You must have Visual Studio installed to complete this step.
3. Open the generated `.sln` file. This is the Visual Studio solution file that's been generated by Unreal Engine.

### 2. Modifying Build Files

1. Add "Kronos" to PublicDependencyModuleNames in `LyraGame.Build.cs`.
2. Comment out the NativePointerMemberBehaviorOverride line in `LyraEditor.Target.cs` file by placing two slash (//) characters before it. Currently Kronos does not make use of the `TObjectPtr` type for backwards compatibility reasons.

<figure><img src="/files/VgzH3GsdvIexm4SbGuPT" alt=""><figcaption></figcaption></figure>

### 3. Disabling The Common Session Subsystem

1. Open the `CommonSessionSubsystem.cpp` file. You can press Ctrl+T to quickly find files in the solution.
2. Find the "Initialize" function. You can press Ctrl+F to quickly find the line.
3. Comment out the "BindOnlineDelegates" and "FCoreUObjectDelegates::PostLoadMapWithWorld" lines by placing two slash (//) characters before them.

<figure><img src="/files/iPTlxBQ7W64nQzH76YO1" alt=""><figcaption></figcaption></figure>

### 4. Configuring The Project

1. Follow the steps outlined in the [**Configuration**](/kronos-matchmaking/configuration.md) page of the documentation.
2. Override the Online Session class in `LyraGameInstance` to use `KronosOnlineSession`. You may have already done this during the previous step, but it is important to do this in Lyra's game instance class since it is integrated into the project on a C++ level.
3. Open the `DefaultEngine.ini` file and make sure to set `bUseBeacons` to false under the CommonSessionSubsystem config section. Kronos uses its own set of Online Beacons for matchmaking so Lyra should not handle this.

<figure><img src="/files/uczPE8Ep6taWqI28uWCz" alt=""><figcaption></figcaption></figure>

### 5. Build The Project

1. Now you'll need to rebuild the project. To do this simply press Ctrl+B on your keyboard, or in the top menu press Build -> Build Solution. Please note that this may take a while...
2. If the build succeeded you can start the project and begin using Kronos Matchmaking!

## Implementing Authentication

Since Lyra already handles authentication for us, we will have to make sure that Kronos does not interfere in any way. To do this, go to **Edit -> Project Settings -> Kronos Matchmaking**, and under authentication enable the "AuthenticateUserAutomatically" and "AuthenticationIsPassthrough" options. The latter is hidden inside the Advanced dropdown.

<figure><img src="/files/hA4Xh37X91nF4kdYgflr" alt=""><figcaption></figcaption></figure>

## Implementing Matchmaking

Lyra has its matchmaking functionality started from widget blueprints such as the experience selection screen and the host session screen. You will need to open up those widgets and replace the matchmaking nodes found in them with their Kronos counterparts.

* Hook up `CreateKronosMatch` in "UI/Menu/Experiences/W\_HostSessionScreen" for when an experience was selected: <https://blueprintue.com/blueprint/f34jju17/>
* Hook up `StartKronosMatchmaking` in "UI/Menu/Experiences/W\_ExperienceSelectionScreen" for the quickplay button: <https://blueprintue.com/blueprint/__brjfzz/>
* Hook up `CancelKronosMatchmaking` in "UI/Menu/Experiences/W\_ExperienceSelectionScreen" for when the widget is deactivated: <https://blueprintue.com/blueprint/oobjpcza/>

{% hint style="info" %}
Blueprint nodes for the examples above do not render perfectly on the website, but they will give you a good idea about what you need to change. If you need further assistance please reach out directly.
{% endhint %}

## Fix Reservation Cleanup

Lyra does not use the standard way of disconnecting from online matches through the `HandleDisconnect` function. I assume Epic did this to allow sending parameters to the main menu map when returning. For now we will have to call `DestroyReservationBeacons` manually.

* Hook up `DestroyReservationBeacons` in "UI/Hud/W\_LyraGameMenu" for when the return button is clicked and the open level call has been made. Maps are always loaded in the next frame so it is safe to handle this at the end: <https://blueprintue.com/blueprint/busdki-e/>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://horizongames.gitbook.io/kronos-matchmaking/guides/integrating-with-lyra-game.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
