

# Integrate a game server with Amazon GameLift Servers
<a name="gamelift-sdk-server"></a>

Your custom game server must be able to interact with Amazon GameLift Servers when deployed and running on hosting resources. The topics in this section describes how to integrate your game server project with the server SDK for Amazon GameLift Servers to add required and optional functionality. This section includes general instructions that you can use with any of the language-specific server SDKs. It also includes detailed guidance on integrating your Unreal Engine and Unity game projects. 

**Topics**
+ [Add Amazon GameLift Servers to your game server with the server SDK](gamelift-sdk-server-api.md)
+ [Integrate the server SDK for game engines](integration-engines.md)

# Add Amazon GameLift Servers to your game server with the server SDK
<a name="gamelift-sdk-server-api"></a>

This topic provides general guidance on the server SDK functionality that you need to add to your game server code/ This functionality enables game server processes to communicate with the Amazon GameLift Servers service. Use these instructions for game servers that you plan to deploy onto Amazon GameLift Servers managed EC2 fleets, managed container fleets, or Anywhere fleets. 

Game server processes communicate with the Amazon GameLift Servers service to receive instructions from the service and to report server process health and game session status. For detailed information on interactions between your game hosting solution components (game server, backend service, game client, and Amazon GameLift Servers), see [Game client/server interactions with Amazon GameLift Servers](gamelift-sdk-interactions.md).

**Get the server SDK**

To prepare your game for hosting, add the server SDK for Amazon GameLift Servers to your game server project. The Server SDK is available in several languages. For more information about tool support for game servers, including the server SDK, see [Get Amazon GameLift Servers development tools](gamelift-supported.md).

Download the server SDK for your development language from [github.com/amazon-gamelift](https://github.com/amazon-gamelift). You can find repos for the server SDK versions, plugins, and other development tools.

**Note**  
If you're developing using Unreal Engine or Unity, download the Amazon GameLift Servers plugin for these game engines. The server SDK is built in and ready to use. See these links for additional information:  
Unreal Engine ([Download plugin](https://github.com/amazon-gamelift/amazon-gamelift-plugin-unreal)) ([Integration guide](integration-engines-setup-unreal.md))
Unity ([Download plugin](https://github.com/amazon-gamelift/amazon-gamelift-plugin-unity)) ([Integration guide](integration-engines-unity-using.md))

Server SDK API references:
+ [C\$1\$1 server SDK 5.x for Amazon GameLift Servers -- Actions](integration-server-sdk5-cpp-actions.md)
+ [C\$1 server SDK 5.x for Amazon GameLift Servers -- Actions](integration-server-sdk5-csharp-actions.md)
+ [C\$1\$1 (Unreal) server SDK 5.x for Amazon GameLift Servers -- Actions](integration-server-sdk5-unreal-actions.md)
+ [Go server SDK for Amazon GameLift Servers -- Actions](integration-server-sdk-go-actions.md)

## Initialize the server process
<a name="gamelift-sdk-server-initialize"></a>

Add code to establish communication with Amazon GameLift Servers service and report when the game server process is ready to host a game session. This code must run before any Amazon GameLift Servers code.

1. Initialize an Amazon GameLift Servers API client by calling `InitSdk()`. If you're preparing your game server to run on Amazon GameLift Servers managed EC2 fleets, use the default `InitSDK()`  ([C\$1\$1](integration-server-sdk5-cpp-actions.md#integration-server-sdk5-cpp-initsdk)) ([C\$1](integration-server-sdk5-csharp-actions.md#integration-server-sdk5-csharp-initsdk)) ([Unreal](integration-server-sdk5-unreal-actions.md#integration-server-sdk5-unreal-initsdk)) ([Go](integration-server-sdk-go-actions.md#integration-server-sdk-go-initsdk))  with no parameters. The API client handles connection to the Amazon GameLift Servers service for you. 
**If you're preparing your game server for use on an Amazon GameLift Servers Anywhere fleet:**  
Initialize the Amazon GameLift Servers API client by calling `InitSdk()` with the following `ServerParameters`:  
The URL of the websocket used to connect to your game server.
The ID of the process used to host your game server.
The ID of the compute hosting your game server processes.
The ID of the fleet containing your Amazon GameLift Servers Anywhere compute.
The authorization token generated by the Amazon GameLift Servers operation `[GetComputeAuthToken](https://docs.aws.amazon.com/gameliftservers/latest/apireference/API_GetComputeAuthToken.html)`.

1. Notify the service that the game server process is ready to host a game session. Call `ProcessReady()`  ([C\$1\$1](integration-server-sdk5-cpp-actions.md#integration-server-sdk5-cpp-processready)) ([C\$1](integration-server-sdk5-csharp-actions.md#integration-server-sdk5-csharp-processready)) ([Unreal](integration-server-sdk5-unreal-actions.md#integration-server-sdk5-unreal-processready)) ([Go](integration-server-sdk-go-actions.md#integration-server-sdk-go-processready))  with the following `ProcessParameters`. Each game server process must call `ProcessReady()` only once.
   + The port number for the server process. When the server process starts a game session, it provides the port to the Amazon GameLift Serversservice, which updates the game session information. Your game can retrieve this information and provide it to game clients, which use it to connect to the server process and join the game session.
   + The locations of files that you want Amazon GameLift Servers to store for you. These might include game session logs and other files that the server process generates during a game session. Although Amazon GameLift Servers saves these files temporarily on the compute where the server process is running, these are only available until the instance shuts down. You can access stored files through the [Amazon GameLift Servers console](https://console.aws.amazon.com/gamelift) or by calling the Amazon GameLift Servers API operation [GetGameSessionLogUrl()](https://docs.aws.amazon.com/gameliftservers/latest/apireference/API_GetGameSessionLogUrl.html).
**If you're preparing your game server for use on an Amazon GameLift Servers managed containers fleet:**  
You don't need to specify log parameters for a container fleet. Instead, send game session and other log data to standard output. Container fleets automatically capture all container standard output as a log stream.
   + The following callback functions that allow Amazon GameLift Servers to send messages or prompts to a game server process. Your must implement each of these functions in your game server code. For more information, see `ProcessParameters`([C\$1\$1](integration-server-sdk5-cpp-datatypes.md#integration-server-sdk5-cpp-dataypes-process)) ([C\$1](integration-server-sdk5-csharp-datatypes.md#integration-server-sdk5-csharp-dataypes-process)) ([Unreal](integration-server-sdk5-unreal-datatypes.md#integration-server-sdk5-unreal-dataypes-process)) ([Go](integration-server-sdk-go-datatypes.md#integration-server-sdk-go-dataypes-process))  .
     + (Optional) `onHealthCheck` – Amazon GameLift Servers calls this function regularly to request a health status report from the server.
     + `onStartGameSession` – Amazon GameLift Servers calls this function in response to the client request [CreateGameSession()](https://docs.aws.amazon.com/gameliftservers/latest/apireference/API_CreateGameSession.html).
     + `onProcessTerminate` – Amazon GameLift Servers forces the server process to stop, letting it shut down gracefully.
     + (Optional) `onUpdateGameSession` – Amazon GameLift Servers delivers an updated game session object to the game server or provides a status update on a match backfill request. The [FlexMatch backfill](https://docs.aws.amazon.com/gameliftservers/latest/flexmatchguide/match-backfill.html) feature requires this callback.

   You can also set up a game server so that it can securely access other AWS resources that you own or control. For more information, see [Connect your Amazon GameLift Servers hosted game server to other AWS resources](gamelift-sdk-server-resources.md).

## (Optional) Report server process health
<a name="gamelift-sdk-server-health"></a>

Add code to your game server to implement the callback function `onHealthCheck()`. Amazon GameLift Servers invokes this callback method periodically to collect health metrics. To implement this callback function, do the following:
+ Evaluate the health status of the server process. For example, you might report the server process as unhealthy if any external dependencies have failed.
+ Complete the health evaluation and respond to the callback within 60 seconds. If Amazon GameLift Servers doesn't receive a response in that time, it automatically considers the server process to be unhealthy.
+ Return a Boolean value: true for healthy, false for unhealthy.

If you don't implement a health check callback, then Amazon GameLift Servers considers the server process to be healthy unless the server doesn't respond.

The Amazon GameLift Servers service uses server process health to end unhealthy processes and clear up resources. If a server process continues to report as unhealthy or doesn't respond for three consecutive health checks, then the service might shut down the process and start a new one. The service collects metrics on a fleet's server process health.

## (Optional) Get a TLS certificate
<a name="gamelift-sdk-server-getcertificate"></a>

If the server process is running on a fleet that has TLS certificate generation activated, then you can retrieve the TLS certificate to establish a secure connection with a game client and to encrypt client server communication. A copy of the certificate is stored on the instance. To get the file location, call `GetComputeCertificate()`  ([C\$1\$1](integration-server-sdk5-cpp-actions.md#integration-server-sdk5-cpp-getcomputecertificate)) ([C\$1](integration-server-sdk5-csharp-actions.md#integration-server-sdk5-csharp-getcomputecertificate)) ([Unreal](integration-server-sdk5-unreal-actions.md#integration-server-sdk5-unreal-getcomputecertificate)) ([Go](integration-server-sdk-go-actions.md#integration-server-sdk-go-getcomputecertificate))  .

## Start a game session
<a name="gamelift-sdk-server-startsession"></a>

Add code to implement the callback function `onStartGameSession`. Amazon GameLift Servers invokes this callback to start a game session on the server process.

The `onStartGameSession` function takes a [GameSession](https://docs.aws.amazon.com/gameliftservers/latest/apireference/API_GameSession.html) object as an input parameter. This object includes key game session information, such as maximum players. It can also include game data and player data. The function implementation should do the following tasks:
+ Initiate actions to create a new game session based on the `GameSession` properties. At minimum, the game server must associate the game session ID, which game clients reference when connecting to the server process.
+ Process game data and player data as needed. This data is in the `GameSession` object.
+ Notify the Amazon GameLift Servers service when a new game session is ready to accept players. Call the server API operation `ActivateGameSession()`  ([C\$1\$1](integration-server-sdk5-cpp-actions.md#integration-server-sdk5-cpp-activategamesession)) ([C\$1](integration-server-sdk5-csharp-actions.md#integration-server-sdk5-csharp-activategamesession)) ([Unreal](integration-server-sdk5-unreal-actions.md#integration-server-sdk5-unreal-activategamesession)) ([Go](integration-server-sdk-go-actions.md#integration-server-sdk-go-activategamesession))  . In response to a successful call, the service changes the game session status to `ACTIVE`.

## (Optional) Validate a new player
<a name="gamelift-sdk-server-validateplayer"></a>

If you're tracking the status of player sessions, then add code to validate a new player when they connect to a game server. Amazon GameLift Servers tracks current players and available game session slots.

For validation, a game client that tries to join a game session must include a player session ID. Amazon GameLift Servers generates this ID when your game starts new game sessions by calling [StartGameSessionPlacement()](https://docs.aws.amazon.com/gameliftservers/latest/apireference/API_StartGameSessionPlacement.html) or [StartMatchmaking()](https://docs.aws.amazon.com/gameliftservers/latest/apireference/API_StartMatchmaking.html). On these requests, an open slot in a game session is reserved for the player session.

When the game server process receives a game client connection request, it calls `AcceptPlayerSession()`  ([C\$1\$1](integration-server-sdk5-cpp-actions.md#integration-server-sdk5-cpp-acceptplayersession)) ([C\$1](integration-server-sdk5-csharp-actions.md#integration-server-sdk5-csharp-acceptplayersession)) ([Unreal](integration-server-sdk5-unreal-actions.md#integration-server-sdk5-unreal-acceptplayersession)) ([Go](integration-server-sdk-go-actions.md#integration-server-sdk-go-acceptplayersession))  with the player session ID. In response, Amazon GameLift Servers verifies that the player session ID corresponds to an open slot reserved in the game session. After Amazon GameLift Servers validates the player session ID, the server process accepts the connection. The player can then join the game session. If Amazon GameLift Servers doesn't validate the player session ID, then the server process denies the connection.

## (Optional) Report a player session ending
<a name="gamelift-sdk-server-droppedplayer"></a>

If you're tracking the status of player sessions, add code to notify Amazon GameLift Servers when a player leaves the game session. This code should run whenever the server process detects a dropped connection. Amazon GameLift Servers uses this notification to track current players and available slots in the game session.

To handle dropped connections in your code, add a call to the server API operation `RemovePlayerSession()`  ([C\$1\$1](integration-server-sdk5-cpp-actions.md#integration-server-sdk5-cpp-removeplayersession)) ([C\$1](integration-server-sdk5-csharp-actions.md#integration-server-sdk5-csharp-removeplayersession)) ([Unreal](integration-server-sdk5-unreal-actions.md#integration-server-sdk5-unreal-removeplayersession)) ([Go](integration-server-sdk-go-actions.md#integration-server-sdk-go-removeplayersession))  with the corresponding player session ID.

## End a game session
<a name="gamelift-sdk-server-shutdownsession"></a>

Add code to the server process shutdown sequence to notify Amazon GameLift Servers when a game session is ending. To recycle and refresh hosting resources, shut down each server process after the game session is complete.

At the start of the server process shutdown code, call the server API operation `ProcessEnding()`  ([C\$1\$1](integration-server-sdk5-cpp-actions.md#integration-server-sdk5-cpp-processending)) ([C\$1](integration-server-sdk5-csharp-actions.md#integration-server-sdk5-csharp-processending)) ([Unreal](integration-server-sdk5-unreal-actions.md#integration-server-sdk5-unreal-processending)) ([Go](integration-server-sdk-go-actions.md#integration-server-sdk-go-processending))  g . This call notifies Amazon GameLift Servers that the server process is shutting down. Amazon GameLift Servers changes the game session status and server process status to `TERMINATED`. After calling `ProcessEnding()`, it's safe for the process to shut down.

## Respond to a server process shutdown notification
<a name="gamelift-sdk-server-terminate"></a>

Add code to shut down the server process in response to a notification from the Amazon GameLift Servers service. The service sends this notification when the server process consistently reports unhealthy, or if the instance where the server process is running is being terminated. Amazon GameLift Servers can stop an instance as part of a capacity scale-down event, or in response to Spot Instance interruption. A Spot Instance interruption provides a two-minute notice, which gives the server process time to disconnect players gracefully, preserve game state data, and perform other cleanup tasks.

To handle a shutdown notification, make the following changes to your game server code:
+ Implement the callback function `onProcessTerminate()`  ([C\$1\$1](integration-server-sdk5-cpp-datatypes.md#integration-server-sdk5-cpp-dataypes-process)) ([C\$1](integration-server-sdk5-csharp-datatypes.md#integration-server-sdk5-csharp-dataypes-process)) ([Unreal](integration-server-sdk5-unreal-datatypes.md#integration-server-sdk5-unreal-dataypes-process)) ([Go](integration-server-sdk-go-datatypes.md#integration-server-sdk-go-dataypes-process))  . This function should call code that shuts down the server process.
+ Call the server API operation `GetTerminationTime()`  ([C\$1\$1](integration-server-sdk5-cpp-actions.md#integration-server-sdk5-cpp-getterm)) ([C\$1](integration-server-sdk5-csharp-actions.md#integration-server-sdk5-csharp-getterm)) ([Unreal](integration-server-sdk5-unreal-actions.md#integration-server-sdk5-unreal-getterm)) ([Go](integration-server-sdk-go-actions.md#integration-server-sdk-go-getterm))  from your game server shutdown code. If Amazon GameLift Servers has issued a call to stop the server process, then `GetTerminationTime()` returns the estimated termination time.
+ At the start of your game server shutdown code, call the server API operation `ProcessEnding()`  ([C\$1\$1](integration-server-sdk5-cpp-actions.md#integration-server-sdk5-cpp-processending)) ([C\$1](integration-server-sdk5-csharp-actions.md#integration-server-sdk5-csharp-processending)) ([Unreal](integration-server-sdk5-unreal-actions.md#integration-server-sdk5-unreal-processending)) ([Go](integration-server-sdk-go-actions.md#integration-server-sdk-go-processending))  . This call notifies the Amazon GameLift Servers service that the server process is shutting down. The service then changes the server process status to `TERMINATED`. After calling `ProcessEnding()`, it's safe for the process to shut down.

# Integrate the server SDK for game engines
<a name="integration-engines"></a>

You can use the managed Amazon GameLift Servers service with most major game engines that support C\$1\$1 or C\$1 libraries, including O3DE, Unreal Engine, and Unity. Build the version you need for your game; see the README files with each version for build instructions and minimum requirements. For more information on available Amazon GameLift Servers SDKs, supported development platforms and operating systems, see [Get Amazon GameLift Servers development tools](gamelift-supported.md) for game servers.

In addition to the engine-specific information provided in this topic, find additional help with integrating Amazon GameLift Servers into your game servers, clients and services in the following topics:
+ [Add Amazon GameLift Servers to your game server with the server SDK](gamelift-sdk-server-api.md) – Detailed instructions on integrating Amazon GameLift Servers into a game server.
+ [Integrate Amazon GameLift Servers game client functionality](gamelift-sdk-client-api.md) – Detailed instructions on integrating into a game client or service, including creating game sessions and joining players to games.

## Unreal Engine
<a name="integration-engines-unreal"></a>

**Game servers**  
Prepare your game servers for hosting on Amazon GameLift Servers by adding the [server SDK for Amazon GameLift Servers for Unreal Engine](integration-server-sdk5-unreal-actions.md) to your project and implementing the required server functionality. For help setting up the Unreal Engine plugin and adding Amazon GameLift Servers code, see [Integrate Amazon GameLift Servers into an Unreal Engine project](integration-engines-setup-unreal.md).

**Game clients and services**  
Enable your game clients and/or game services to interact with Amazon GameLift Servers service, such as to find available game sessions or create new ones, and add players to games. Core client functionality is provided in the [AWS SDK for C\$1\$1](https://sdk.amazonaws.com/cpp/api/LATEST/namespace_aws_1_1_game_lift.html). To integrate Amazon GameLift Servers into your Unreal Engine game project, see [Integrate Amazon GameLift Servers game client functionality](gamelift-sdk-client-api.md).

## Unity
<a name="integration-engines-unity"></a>

**Game servers**  
Prepare your game servers for hosting on Amazon GameLift Servers by adding the [server SDK for Amazon GameLift Servers for C\$1](integration-server-sdk5-csharp-actions.md) to your project and implementing the required server functionality. For help setting up with Unity and adding Amazon GameLift Servers code, see [Integrate Amazon GameLift Servers into a Unity project](integration-engines-unity-using.md).

**Game clients and services**  
Enable your game clients and/or game services to interact with Amazon GameLift Servers service, such as to find available game sessions or create new ones, and add players to games. Core client functionality is provided in the [AWS SDK for .NET](https://docs.aws.amazon.com/sdkfornet/v3/apidocs/). To integrate Amazon GameLift Servers into your Unity game project, see [Integrate Amazon GameLift Servers game client functionality](gamelift-sdk-client-api.md).

## Other engines
<a name="integration-engines-other"></a>

For a full list of the Amazon GameLift Servers SDKs available for game servers and clients, see [Get Amazon GameLift Servers development tools](gamelift-supported.md).

# Integrate Amazon GameLift Servers into an Unreal Engine project
<a name="integration-engines-setup-unreal"></a>

Learn how to integrate the Amazon GameLift Servers SDK for Unreal Engine into your game projects to access the full server SDK feature set. 

**Tip**  
For faster deployment, try the Amazon GameLift Servers standalone plugin for Unreal Engine. It provides guided UI workflows to quickly deploy your game server with minimal setup, so you can try out your game components in action. See [Amazon GameLift Servers plugin for Unreal Engine](unreal-plugin.md).

Additional resources: 
+ [C\$1\$1 (Unreal) server SDK 5.x for Amazon GameLift Servers -- Actions](integration-server-sdk5-unreal-actions.md)
+ [Get Amazon GameLift Servers development tools](gamelift-supported.md)

## Install the server SDK for Unreal
<a name="integration-engines-setup-unreal-install"></a>

Get the open-source Amazon GameLift Servers SDK for Unreal Engine from [GitHub](https://github.com/amazon-gamelift/amazon-gamelift-plugin-unreal). The repository's readme files contain prerequisites and installation instructions.

## Set up build targets and module rules
<a name="integration-engines-setup-unreal-setup"></a>

Modify your game project files to properly generate build components for use with Amazon GameLift Servers.

**To add client and server build targets:**

1. Open your game project's code files and locate the file `.../Games/[your application name]Source/[your application name]Target.cs` file. Example: `.../Source/GameLiftUnrealAppTarget.cs`. (If you use Visual Studio, open the project's `.sln` file.)

1. Copy this file to create two new target files in the `Source/` directory. 
   + Client target – Rename the new file to `[your application name]Client.Target.cs`. Edit the contents to update the class name and target type values, as illustrated in the following sample code: 

     ```
     using UnrealBuildTool;
       using System.Collections.Generic;
     
       public class GameLiftUnrealAppClientTarget :  TargetRules
      {
          public GameLiftUnrealAppClientTarget ( TargetInfo Target ) :  base ( Target )
          {
              Type = TargetType.Client;
              DefaultBuildSettings = BuildSettingsVersion.V2;
              IncludeOrderVersion = EngineIncludeOrderVersion.Unreal5_1;
              ExtraModuleNames.Add( "GameLiftUnrealApp");
          }
      }
     ```
   + Server target – Rename the new file to `[your application name]Server.Target.cs`. Edit the contents to update the class name and target type values, as illustrated in the following sample code: 

     ```
     using UnrealBuildTool;
       using System.Collections.Generic;
     
       public class GameLiftUnrealAppServerTarget :  TargetRules
      {
          public GameLiftUnrealAppServerTarget ( TargetInfo Target ) :  base ( Target )
          {
              Type = TargetType.Server;
              DefaultBuildSettings = BuildSettingsVersion.V2;
              IncludeOrderVersion = EngineIncludeOrderVersion.Unreal5_1;
              ExtraModuleNames.Add( "GameLiftUnrealApp");
          }
      }
     ```

1. Regenerate your project files. If you're using Visual Studio, you can right-click your game project's `.uproject` file and select **Generate Visual Studio Project Files**.

**To update the game project module rules:**

Update the game project's module rules to take a dependency on the plugin.

1. Open your game project's code files and locate the file `.../Games/[your application name]Source/[your application name].Build.cs` file. Example: `.../Source/GameLiftUnrealApp.Build.cs`. (If you use Visual Studio, open the project's `.sln` file.)

1. Locate the `ModuleRules` class and update as illustrated in the following sample code: 

   ```
   using UnrealBuildTool;
   
     public class GameLiftUnrealApp :  ModuleRules
    {
        public GameLiftUnrealApp ( ReadOnlyTargetRules Target ) :  base ( Target )
        {
            PCHUsage = PCHUsageMode.UseExplicitOrSharedPCHs;
            PublicDependencyModuleNames.AddRange( new string[] {  "Core",  "CoreUObject",  "Engine",  "InputCore",  "HeadMountedDisplay",  "EnhancedInput" });
         // Add the following section
            if (Target.Type == TargetType.Server)
            {
                PublicDependencyModuleNames.Add("GameLiftServerSDK");
            }
            else
            {
                PublicDefinitions.Add("WITH_GAMELIFT=0");
            }
            bEnableExceptions =  true;
        }
    }
   ```

1. After creating the new target files and modifying the module rules, rebuild your game project.

## Add game hosting functionality to your server code
<a name="integration-engines-setup-unreal-code"></a>

After server SDK installation and setup, the next step is to integrate game hosting functionality into your server code. The server SDK enables your game server to communicate with the Amazon GameLift Servers service, receive instructions for game sessions, report status and health, and perform other actions.

This topic provides sample code that adds the minimum functionality required to host your game with Amazon GameLift Servers. 

**Step 1: Update the `GameMode` header file**

1. Open your game project's code files and locate the file `Your-application-nameGameMode.h` file. Example: `GameLiftUnrealAppGameMode.h`. If you use Visual Studio, open the `.sln` file for your game project.

1. Change the header file to include the following example code. Be sure to replace "GameLiftUnrealApp" with your own application name.

### Sample code for GameMode.h
<a name="w2aab9c11c11b9c17c15b9b1"></a>

```
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

#pragma once

#include "CoreMinimal.h"
#include "GameFramework/GameModeBase.h"
#include "GameLiftUnrealAppGameMode.generated.h"

struct FProcessParameters;

DECLARE_LOG_CATEGORY_EXTERN(GameServerLog, Log, All);

UCLASS(minimalapi)
class AGameLiftUnrealAppGameMode : public AGameModeBase
{
    GENERATED_BODY()

public:
    AGameLiftUnrealAppGameMode();

protected:
    virtual void BeginPlay() override;

private:
    void InitGameLift();

private:
    TSharedPtr<FProcessParameters> ProcessParameters;
};
```

**Step 2: Add required server SDK calls to your game server code**

Use the sample code in this section to integrate your game server code for use with Amazon GameLift Servers. For details on what the code does, see [Initialize the server process](gamelift-sdk-server-api.md#gamelift-sdk-server-initialize) and [C\$1\$1 (Unreal) server SDK 5.x for Amazon GameLift Servers -- Actions](integration-server-sdk5-unreal-actions.md).
**Note**  
The `WITH_GAMELIFT` preprocessor flag serves two purposes:  
Restricts Amazon GameLift Servers backend API calls to Unreal server builds only
Ensures compatibility across different Unreal build targets

1. Open the related source file `Your-application-nameGameMode.cpp` file. In our example: `GameLiftUnrealAppGameMode.cpp`. 

1. Change the code to align with the following example code. Be sure to replace any instance of "GameLiftUnrealApp" with your own application name.

   The code sample provided shows how to add the required elements for integration with Amazon GameLift Servers. These include:
   + Initialize an Amazon GameLift Servers API client.
   + Implement callback functions to respond to requests from the Amazon GameLift Servers service, including `OnStartGameSession`, `OnProcessTerminate`, and `onHealthCheck`.
   + Call `ProcessReady()` to notify the Amazon GameLift Servers service when ready to host game sessions.

### Sample code for GameMode.cpp
<a name="w2aab9c11c11b9c17c15c13b1"></a>

```
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

#include "GameLiftUnrealAppGameMode.h"

#include "UObject/ConstructorHelpers.h"
#include "Kismet/GameplayStatics.h"

#if WITH_GAMELIFT
#include "GameLiftServerSDK.h"
#include "GameLiftServerSDKModels.h"
#endif

#include "GenericPlatform/GenericPlatformOutputDevices.h"

DEFINE_LOG_CATEGORY(GameServerLog);

AGameLiftUnrealAppGameMode::AGameLiftUnrealAppGameMode() :
    ProcessParameters(nullptr)
{
    // Set default pawn class to our Blueprinted character
    static ConstructorHelpers::FClassFinder<APawn> PlayerPawnBPClass(TEXT("/Game/ThirdPerson/Blueprints/BP_ThirdPersonCharacter"));

    if (PlayerPawnBPClass.Class != NULL)
    {
        DefaultPawnClass = PlayerPawnBPClass.Class;
    }

    UE_LOG(GameServerLog, Log, TEXT("Initializing AGameLiftUnrealAppGameMode..."));
}

void AGameLiftUnrealAppGameMode::BeginPlay()
{
    Super::BeginPlay();

#if WITH_GAMELIFT
    InitGameLift();
#endif
}

void AGameLiftUnrealAppGameMode::InitGameLift()
{
#if WITH_GAMELIFT
    UE_LOG(GameServerLog, Log, TEXT("Calling InitGameLift..."));

    // Getting the module first.
    FGameLiftServerSDKModule* GameLiftSdkModule = &FModuleManager::LoadModuleChecked<FGameLiftServerSDKModule>(FName("GameLiftServerSDK"));

    //Define the server parameters for a GameLift Anywhere fleet. These are not needed for a GameLift managed EC2 fleet.
    FServerParameters ServerParametersForAnywhere;

    bool bIsAnywhereActive = false;
    if (FParse::Param(FCommandLine::Get(), TEXT("glAnywhere")))
    {
        bIsAnywhereActive = true;
    }

    if (bIsAnywhereActive)
    {
        UE_LOG(GameServerLog, Log, TEXT("Configuring server parameters for Anywhere..."));

        // If GameLift Anywhere is enabled, parse command line arguments and pass them in the ServerParameters object.
        FString glAnywhereWebSocketUrl = "";
        if (FParse::Value(FCommandLine::Get(), TEXT("glAnywhereWebSocketUrl="), glAnywhereWebSocketUrl))
        {
            ServerParametersForAnywhere.m_webSocketUrl = TCHAR_TO_UTF8(*glAnywhereWebSocketUrl);
        }

        FString glAnywhereFleetId = "";
        if (FParse::Value(FCommandLine::Get(), TEXT("glAnywhereFleetId="), glAnywhereFleetId))
        {
            ServerParametersForAnywhere.m_fleetId = TCHAR_TO_UTF8(*glAnywhereFleetId);
        }

        FString glAnywhereProcessId = "";
        if (FParse::Value(FCommandLine::Get(), TEXT("glAnywhereProcessId="), glAnywhereProcessId))
        {
            ServerParametersForAnywhere.m_processId = TCHAR_TO_UTF8(*glAnywhereProcessId);
        }
        else
        {
            // If no ProcessId is passed as a command line argument, generate a randomized unique string.
            FString TimeString = FString::FromInt(std::time(nullptr));
            FString ProcessId = "ProcessId_" + TimeString;
            ServerParametersForAnywhere.m_processId = TCHAR_TO_UTF8(*ProcessId);
        }

        FString glAnywhereHostId = "";
        if (FParse::Value(FCommandLine::Get(), TEXT("glAnywhereHostId="), glAnywhereHostId))
        {
            ServerParametersForAnywhere.m_hostId = TCHAR_TO_UTF8(*glAnywhereHostId);
        }

        FString glAnywhereAuthToken = "";
        if (FParse::Value(FCommandLine::Get(), TEXT("glAnywhereAuthToken="), glAnywhereAuthToken))
        {
            ServerParametersForAnywhere.m_authToken = TCHAR_TO_UTF8(*glAnywhereAuthToken);
        }

        FString glAnywhereAwsRegion = "";
        if (FParse::Value(FCommandLine::Get(), TEXT("glAnywhereAwsRegion="), glAnywhereAwsRegion))
        {
            ServerParametersForAnywhere.m_awsRegion = TCHAR_TO_UTF8(*glAnywhereAwsRegion);
        }

        FString glAnywhereAccessKey = "";
        if (FParse::Value(FCommandLine::Get(), TEXT("glAnywhereAccessKey="), glAnywhereAccessKey))
        {
            ServerParametersForAnywhere.m_accessKey = TCHAR_TO_UTF8(*glAnywhereAccessKey);
        }

        FString glAnywhereSecretKey = "";
        if (FParse::Value(FCommandLine::Get(), TEXT("glAnywhereSecretKey="), glAnywhereSecretKey))
        {
            ServerParametersForAnywhere.m_secretKey = TCHAR_TO_UTF8(*glAnywhereSecretKey);
        }

        FString glAnywhereSessionToken = "";
        if (FParse::Value(FCommandLine::Get(), TEXT("glAnywhereSessionToken="), glAnywhereSessionToken))
        {
            ServerParametersForAnywhere.m_sessionToken = TCHAR_TO_UTF8(*glAnywhereSessionToken);
        }

        UE_LOG(GameServerLog, SetColor, TEXT("%s"), COLOR_YELLOW);
        UE_LOG(GameServerLog, Log, TEXT(">>>> WebSocket URL: %s"), *ServerParametersForAnywhere.m_webSocketUrl);
        UE_LOG(GameServerLog, Log, TEXT(">>>> Fleet ID: %s"), *ServerParametersForAnywhere.m_fleetId);
        UE_LOG(GameServerLog, Log, TEXT(">>>> Process ID: %s"), *ServerParametersForAnywhere.m_processId);
        UE_LOG(GameServerLog, Log, TEXT(">>>> Host ID (Compute Name): %s"), *ServerParametersForAnywhere.m_hostId);
        UE_LOG(GameServerLog, Log, TEXT(">>>> Auth Token: %s"), *ServerParametersForAnywhere.m_authToken);
        UE_LOG(GameServerLog, Log, TEXT(">>>> Aws Region: %s"), *ServerParametersForAnywhere.m_awsRegion);
        UE_LOG(GameServerLog, Log, TEXT(">>>> Access Key: %s"), *ServerParametersForAnywhere.m_accessKey);
        UE_LOG(GameServerLog, Log, TEXT(">>>> Secret Key: %s"), *ServerParametersForAnywhere.m_secretKey);
        UE_LOG(GameServerLog, Log, TEXT(">>>> Session Token: %s"), *ServerParametersForAnywhere.m_sessionToken);
        UE_LOG(GameServerLog, SetColor, TEXT("%s"), COLOR_NONE);
    }

    UE_LOG(GameServerLog, Log, TEXT("Initializing the GameLift Server..."));

    //InitSDK will establish a local connection with GameLift's agent to enable further communication.
    FGameLiftGenericOutcome InitSdkOutcome = GameLiftSdkModule->InitSDK(ServerParametersForAnywhere);
    if (InitSdkOutcome.IsSuccess())
    {
        UE_LOG(GameServerLog, SetColor, TEXT("%s"), COLOR_GREEN);
        UE_LOG(GameServerLog, Log, TEXT("GameLift InitSDK succeeded!"));
        UE_LOG(GameServerLog, SetColor, TEXT("%s"), COLOR_NONE);
    }
    else
    {
        UE_LOG(GameServerLog, SetColor, TEXT("%s"), COLOR_RED);
        UE_LOG(GameServerLog, Log, TEXT("ERROR: InitSDK failed : ("));
        FGameLiftError GameLiftError = InitSdkOutcome.GetError();
        UE_LOG(GameServerLog, Log, TEXT("ERROR: %s"), *GameLiftError.m_errorMessage);
        UE_LOG(GameServerLog, SetColor, TEXT("%s"), COLOR_NONE);
        return;
    }

    ProcessParameters = MakeShared<FProcessParameters>();

    //When a game session is created, Amazon GameLift Servers sends an activation request to the game server and passes along the game session object containing game properties and other settings.
    //Here is where a game server should take action based on the game session object.
    //Once the game server is ready to receive incoming player connections, it should invoke GameLiftServerAPI.ActivateGameSession()
    ProcessParameters->OnStartGameSession.BindLambda([=](Aws::GameLift::Server::Model::GameSession InGameSession)
        {
            FString GameSessionId = FString(InGameSession.GetGameSessionId());
            UE_LOG(GameServerLog, Log, TEXT("GameSession Initializing: %s"), *GameSessionId);
            GameLiftSdkModule->ActivateGameSession();
        });

    //OnProcessTerminate callback. Amazon GameLift Servers will invoke this callback before shutting down an instance hosting this game server.
    //It gives this game server a chance to save its state, communicate with services, etc., before being shut down.
    //In this case, we simply tell Amazon GameLift Servers we are indeed going to shut down.
    ProcessParameters->OnTerminate.BindLambda([=]()
        {
            UE_LOG(GameServerLog, Log, TEXT("Game Server Process is terminating"));
            // First call ProcessEnding()
            FGameLiftGenericOutcome processEndingOutcome = GameLiftSdkModule->ProcessEnding();
            // Then call Destroy() to free the SDK from memory
            FGameLiftGenericOutcome destroyOutcome = GameLiftSdkModule->Destroy();
            // Exit the process with success or failure
            if (processEndingOutcome.IsSuccess() && destroyOutcome.IsSuccess()) {
                UE_LOG(GameServerLog, Log, TEXT("Server process ending successfully"));
            }
            else {
                if (!processEndingOutcome.IsSuccess()) {
                    const FGameLiftError& error = processEndingOutcome.GetError();
                    UE_LOG(GameServerLog, Error, TEXT("ProcessEnding() failed. Error: %s"),
                    error.m_errorMessage.IsEmpty() ? TEXT("Unknown error") : *error.m_errorMessage);
                }
                if (!destroyOutcome.IsSuccess()) {
                    const FGameLiftError& error = destroyOutcome.GetError();
                    UE_LOG(GameServerLog, Error, TEXT("Destroy() failed. Error: %s"),
                    error.m_errorMessage.IsEmpty() ? TEXT("Unknown error") : *error.m_errorMessage);
                }
            }
        });
         
    //This is the HealthCheck callback.
    //Amazon GameLift Servers will invoke this callback every 60 seconds or so.
    //Here, a game server might want to check the health of dependencies and such.
    //Simply return true if healthy, false otherwise.
    //The game server has 60 seconds to respond with its health status. Amazon GameLift Servers will default to 'false' if the game server doesn't respond in time.
    //In this case, we're always healthy!
    ProcessParameters->OnHealthCheck.BindLambda([]()
        {
            UE_LOG(GameServerLog, Log, TEXT("Performing Health Check"));
            return true;
        });

    //GameServer.exe -port=7777 LOG=server.mylog
    ProcessParameters->port = FURL::UrlConfig.DefaultPort;
    TArray<FString> CommandLineTokens;
    TArray<FString> CommandLineSwitches;

    FCommandLine::Parse(FCommandLine::Get(), CommandLineTokens, CommandLineSwitches);

    for (FString SwitchStr : CommandLineSwitches)
    {
        FString Key;
        FString Value;

        if (SwitchStr.Split("=", &Key, &Value))
        {
            if (Key.Equals("port"))
            {
                ProcessParameters->port = FCString::Atoi(*Value);
            }
        }
    }

    //Here, the game server tells Amazon GameLift Servers where to find game session log files.
    //At the end of a game session, Amazon GameLift Servers uploads everything in the specified 
    //location and stores it in the cloud for access later.
    TArray<FString> Logfiles;
    Logfiles.Add(TEXT("GameLiftUnrealApp/Saved/Logs/server.log"));
    ProcessParameters->logParameters = Logfiles;

    //The game server calls ProcessReady() to tell Amazon GameLift Servers it's ready to host game sessions.
    UE_LOG(GameServerLog, Log, TEXT("Calling Process Ready..."));
    FGameLiftGenericOutcome ProcessReadyOutcome = GameLiftSdkModule->ProcessReady(*ProcessParameters);

    if (ProcessReadyOutcome.IsSuccess())
    {
        UE_LOG(GameServerLog, SetColor, TEXT("%s"), COLOR_GREEN);
        UE_LOG(GameServerLog, Log, TEXT("Process Ready!"));
        UE_LOG(GameServerLog, SetColor, TEXT("%s"), COLOR_NONE);
    }
    else
    {
        UE_LOG(GameServerLog, SetColor, TEXT("%s"), COLOR_RED);
        UE_LOG(GameServerLog, Log, TEXT("ERROR: Process Ready Failed!"));
        FGameLiftError ProcessReadyError = ProcessReadyOutcome.GetError();
        UE_LOG(GameServerLog, Log, TEXT("ERROR: %s"), *ProcessReadyError.m_errorMessage);
        UE_LOG(GameServerLog, SetColor, TEXT("%s"), COLOR_NONE);
    }

    UE_LOG(GameServerLog, Log, TEXT("InitGameLift completed!"));
#endif
}
```

**Step 3: Rebuild the game project**
+ Build game project for both of the following target types: *Development Editor* and *Development Server*.
**Note**  
You don't need to rebuild the solution. Instead, build the project under the `/Games/` folder for your app. Otherwise, Visual Studio will rebuild the entire UE5 project, which can take up to an hour.

## Package your game server for hosting
<a name="integration-engines-setup-unreal-package"></a>

With your game server code now integrated with the minimum required server SDK functionality, you're ready to package your game server build using the Unreal Editor. 

**To package the game server build**

1. Open the game project in the Unreal Editor.

1. Follow the Unreal Editor steps to package your game server: 
   + Choose your target platform (Windows or Linux).
   + Select your server build target (`[your application name]Server`.

   The packaging process generates your game server executable: `[your application name]Server.exe`. 

1. Prepare your game server build for deployment to hosting resources. The build should include the following files: 
   + Your game server executable
   + If you're using Unreal Engine version 5.5 or older, include the following files for Windows builds. You can find them in your source-built version of the Unreal Engine:
     + `VC_redist.x64.exe` (`UnrealEngine\Engine\Source\Programs\PrereqInstaller\Resources\VCRedist\`)
     + `UEPrereqSetup_x64.exe or UE5PrereqSetup_x64.exe` (`UnrealEngine\Engine\Extras\Redist\en-us\`)
   + All other required dependencies for your game server.
   + OpenSSL libraries, if needed. You can skip this step if your game server is integrated with Amazon GameLift Servers server SDK version 5.3 or later. [The latest server SDK version is available here.](https://github.com/amazon-gamelift/amazon-gamelift-plugin-unreal)

### OpenSSL libraries required for game servers created with server SDK for Unreal, versions 5.2 and earlier
<a name="w2aab9c11c11b9c17c25b7b1"></a>

You must include the same version of OpenSSL libraries that were used when packaging the game server in Unreal. These libraries are located in your game engine source. The location varies depending on your development environment:

On Windows: 
+ `[ENGINE_ROOT_DIR]\Engine\Extras\ThirdPartyNotUE\libimobiledevice\x64\libssl-1_1-x64.dll`
+ `[ENGINE_ROOT_DIR]\Engine\Extras\ThirdPartyNotUE\libimobiledevice\x64\libcrypto-1_1-x64.dll` 

On Linux:
+ `Engine/Source/Thirdparty/OpenSSL/1.1.1n/include/libssl.so.1.1`
+ `Engine/Source/Thirdparty/OpenSSL/1.1.1n/include/libcrypto.so.1.1`

Copy the OpenSSL libraries to your game build package in the same directory as the game server executable file. 

## Next steps
<a name="integration-engines-setup-unreal-next"></a>

Now that you've prepared a game server build with the minimum required functionality for hosting with Amazon GameLift Servers, consider these potential next steps: 
+ Deploy your integrated game server for and testing and development. With an Anywhere fleet, you can set up your local machine as a hosting resource and use it to test your game server and game client connections. For cloud-based hosting, deploy your game server to a managed EC2 or managed container fleet. See these topics for guidance:
  + [Set up for iterative development with Amazon GameLift Servers Anywhere](integration-dev-iteration.md)
  + [Amazon GameLift Servers Anywhere fleets](fleets-intro-anywhere.md)
  + [Amazon GameLift Servers managed EC2 fleets](fleets-intro-managed.md)
  + [Amazon GameLift Servers managed container fleets](fleets-intro-containers.md)
+ Customize your game server integration by adding optional features. For example, you might want to add player sessions with unique player IDs, set up matchmaking backfill, or manage game server access to your other AWS resources (such as a database or content storage service). See these topics for guidance: 
  + [Add Amazon GameLift Servers to your game server with the server SDK](gamelift-sdk-server-api.md)
  + [C\$1\$1 (Unreal) server SDK 5.x for Amazon GameLift Servers -- Actions](integration-server-sdk5-unreal-actions.md)
+ Customize your game client component to request game sessions, receive connection information, and connect directly to a game server to play a game. See these topics for guidance:
  + [Integrate Amazon GameLift Servers game client functionality](gamelift-sdk-client-api.md)

# Integrate Amazon GameLift Servers into a Unity project
<a name="integration-engines-unity-using"></a>

Learn how to integrate the Amazon GameLift Servers SDK for Unity into your game projects to access the full server SDK feature set. 

**Tip**  
For faster deployment, try the Amazon GameLift Servers standalone plugin for Unity. It provides guided UI workflows to quickly deploy your game server with minimal setup, so you can try out your game components in action. See [Amazon GameLift Servers plugin for Unity (server SDK 5.x)](unity-plug-in.md).

Additional resources: 
+ [C\$1 server SDK 5.x for Amazon GameLift Servers -- Actions](integration-server-sdk5-csharp-actions.md)
+ [Get Amazon GameLift Servers development tools](gamelift-supported.md)

## Install the server SDK for Unity
<a name="integration-engines-unity-install"></a>

Get the open-source Amazon GameLift Servers for Unity from [GitHub](https://github.com/amazon-gamelift/amazon-gamelift-plugin-unity). The repository's readme files contain prerequisites and installation instructions.

## Set up an Amazon GameLift Servers Anywhere fleet for testing
<a name="integration-engines-unity-fleet"></a>

You can set up your development workstation as an Amazon GameLift Servers Anywhere hosting fleet to iteratively test your Amazon GameLift Servers integration. With this setup, you can start game server processes on your workstation, send player join or matchmaking requests to Amazon GameLift Servers to start game sessions, and connect clients to the new game sessions. With your own workstation set up as a hosting server, you can monitor all aspects of your game integration with Amazon GameLift Servers.

For instructions on setting up your workstation, see [Set up local testing with Amazon GameLift Servers Anywhere](integration-testing.md) to complete the following steps:

1. Create a custom location for your workstation. 

1. Create an Amazon GameLift Servers Anywhere fleet with your new custom location. If successful, this request returns a fleet ID. Make a note of this value, as you'll need it later.

1. Register your workstation as a compute in the new Anywhere fleet. Provide a unique compute name and specify the IP address for your workstation. If successful, this request returns a service SDK endpoint, in the form of a WebSocket URL. Make a note of this value, as you'll need it later.

1. Generate an authentication token for your workstation compute. This short-lived authentication includes the token and an expiration date. Your game server uses it to authenticate communication with the Amazon GameLift Servers service. Store the authentication on your workstation compute so that your running game server processes can access it. 

## Add Amazon GameLift Servers server code to your Unity project
<a name="integration-engines-unity-code"></a>

Your game server communicates with the Amazon GameLift Servers service to receive instructions and report ongoing status. To accomplish this, you add game server code that uses the Amazon GameLift Servers server SDK. 

The provided code example illustrates the basic required integration elements. It uses a `MonoBehavior` to illustrate a simple game server initialization with Amazon GameLift Servers. The example assumes that the game server runs on an Amazon GameLift Servers Anywhere fleet for testing. It includes code to: 
+ Initialize an Amazon GameLift Servers API client. The sample uses the version of `InitSDK()` with server parameters for your Anywhere fleet and compute. Use the WebSocket URL, fleet ID, compute name (host ID), and authentication token, as defined in the previous topic [Set up an Amazon GameLift Servers Anywhere fleet for testing](#integration-engines-unity-fleet).
+ Implement callback functions to respond to requests from the Amazon GameLift Servers service, including `OnStartGameSession`, `OnProcessTerminate`, and `onHealthCheck`.
+ Call ProcessReady() with a designated port to notify the Amazon GameLift Servers service when the process is ready to host game sessions.

The sample code provided establishes communication with the Amazon GameLift Servers service. It also implements a set of callback functions that respond to requests from the Amazon GameLift Servers service. For more information on each function and what the code does, see [Initialize the server process](https://docs.aws.amazon.com//gameliftservers/latest/developerguide/gamelift-sdk-server-api.html#gamelift-sdk-server-initialize). For more information on the SDK actions and data types used in this code, read [C\$1 server SDK 5.x for Amazon GameLift Servers -- Actions](integration-server-sdk5-csharp-actions.md).

The sample code shows how to add the required functionality, as described in [Add Amazon GameLift Servers to your game server](https://docs.aws.amazon.com//gameliftservers/latest/developerguide/gamelift-sdk-server-api.html). For more information on server SDK actions, see the [C\$1 server SDK 5.x for Amazon GameLift Servers -- Actions](integration-server-sdk5-csharp-actions.md).

### Integration sample code
<a name="w2aab9c11c11b9c19c15c13b1"></a>

```
using System.Collections.Generic;
using Aws.GameLift.Server;
using UnityEngine;

public class ServerSDKManualTest : MonoBehaviour
{    
    //This example is a simple integration that initializes a game server process 
    //that is running on an Amazon GameLift Servers Anywhere fleet.
    void Start()
    {        
        //Identify port number (hard coded here for simplicity) the game server is listening on for player connections
        var listeningPort = 7777;

        //WebSocketUrl from RegisterHost call
        var webSocketUrl = "wss://us-west-2.api.amazongamelift.com";

        //Unique identifier for this process
        var processId = "myProcess";

        //Unique identifier for your host that this process belongs to
        var hostId = "myHost";

        //Unique identifier for your fleet that this host belongs to
        var fleetId = "myFleet";

        //Authorization token for this host process
        var authToken = "myAuthToken";

        //Server parameters are required for an Amazon GameLift Servers Anywhere fleet.
        //They are not required for an Amazon GameLift Servers managed EC2 fleet.
        ServerParameters serverParameters = new ServerParameters(
            webSocketUrl,
            processId,
            hostId,
            fleetId,
            authToken);

        //InitSDK establishes a local connection with an Amazon GameLift Servers agent 
        //to enable further communication.
        var initSDKOutcome = GameLiftServerAPI.InitSDK(serverParameters);        
        if (initSDKOutcome.Success)
        {
            //Implement callback functions
            ProcessParameters processParameters = new ProcessParameters(
            //Implement OnStartGameSession callback
                (gameSession) => {
                    //Amazon GameLift Servers sends a game session activation request to the game server 
                    //with game session object containing game properties and other settings.
                    //Here is where a game server takes action based on the game session object.
                    //When the game server is ready to receive incoming player connections, 
                    //it invokes the server SDK call ActivateGameSession().
                    GameLiftServerAPI.ActivateGameSession();
                },
                (updateGameSession) => {
                    //Amazon GameLift Servers sends a request when a game session is updated (such as for 
                    //FlexMatch backfill) with an updated game session object. 
                    //The game server can examine matchmakerData and handle new incoming players.
                    //updateReason explains the purpose of the update.
                },
                () => {
                    //Implement callback function OnProcessTerminate
                    //Amazon GameLift Servers invokes this callback before shutting down the instance hosting this game server.
                    //It gives the game server a chance to save its state, communicate with services, etc., 
                    //and initiate shut down. When the game server is ready to shut down, it invokes the 
                    //server SDK call ProcessEnding() to tell Amazon GameLift Servers it is shutting down.
                    GameLiftServerAPI.ProcessEnding();
                }, 
                () => {
                    //Implement callback function OnHealthCheck
                    //Amazon GameLift Servers invokes this callback approximately every 60 seconds.
                    //A game server might want to check the health of dependencies, etc.
                    //Then it returns health status true if healthy, false otherwise.
                    //The game server must respond within 60 seconds, or Amazon GameLift Servers records 'false'.
                    //In this example, the game server always reports healthy.
                    return true;
                },
                //The game server gets ready to report that it is ready to host game sessions
                //and that it will listen on port 7777 for incoming player connections.
                listeningPort, 
                new LogParameters(new List<string>()
                {
                    //Here, the game server tells Amazon GameLift Servers where to find game session log files.
                    //At the end of a game session, Amazon GameLift Servers uploads everything in the specified 
                    //location and stores it in the cloud for access later.
                    "/local/game/logs/myserver.log"
                }));

            //The game server calls ProcessReady() to tell Amazon GameLift Servers it's ready to host game sessions.
            var processReadyOutcome = GameLiftServerAPI.ProcessReady(processParameters);
            if (processReadyOutcome.Success)
            {
                print("ProcessReady success.");
            }
            else
            {
                print("ProcessReady failure : " + processReadyOutcome.Error.ToString());
            }
        }
        else
        {
            print("InitSDK failure : " + initSDKOutcome.Error.ToString());
        }
    }  

    void OnApplicationQuit()
    {
        //Make sure to call GameLiftServerAPI.ProcessEnding() and GameLiftServerAPI.Destroy() before terminating the server process.
        //These actions notify Amazon GameLift Servers that the process is terminating and frees the API client from memory. 
        GenericOutcome processEndingOutcome = GameLiftServerAPI.ProcessEnding();
        GameLiftServerAPI.Destroy();
        if (processEndingOutcome.Success)
        {
            Environment.Exit(0);
        }
        else
        {
            Console.WriteLine("ProcessEnding() failed. Error: " + processEndingOutcome.Error.ToString());
            Environment.Exit(-1);  
        }
    }
}
```

## Next steps
<a name="integration-engines-unity-additional-resources"></a>

Now that you've prepared a game server build with the minimum required functionality for hosting with Amazon GameLift Servers, consider these potential next steps: 
+ Deploy your integrated game server for and testing and development. With an Anywhere fleet, you can set up your local machine as a hosting resource and use it to test your game server and game client connections. For cloud-based hosting, deploy your game server to a managed EC2 or managed container fleet. See these topics for guidance:
  + [Set up for iterative development with Amazon GameLift Servers Anywhere](integration-dev-iteration.md)
  + [Amazon GameLift Servers Anywhere fleets](fleets-intro-anywhere.md)
  + [Amazon GameLift Servers managed EC2 fleets](fleets-intro-managed.md)
  + [Amazon GameLift Servers managed container fleets](fleets-intro-containers.md)
+ Customize your game server integration by adding optional features. For example, you might want to add player sessions with unique player IDs, set up matchmaking backfill, or manage game server access to your other AWS resources (such as a database or content storage service). See these topics for guidance: 
  + [Add Amazon GameLift Servers to your game server with the server SDK](gamelift-sdk-server-api.md)
  + [C\$1\$1 (Unreal) server SDK 5.x for Amazon GameLift Servers -- Actions](integration-server-sdk5-unreal-actions.md)
+ Customize your game client component to request game sessions, receive connection information, and connect directly to a game server to play a game. See these topics for guidance:
  + [Integrate Amazon GameLift Servers game client functionality](gamelift-sdk-client-api.md)