

# Amazon GameLift Servers plugin for Unreal Engine
<a name="unreal-plugin"></a>

This plugin adds the Amazon GameLift Servers C\$1\$1 server SDK and tools to the UE editor. Use the guided UI workflows to integrate server SDK functionality into your game project and deploy an Amazon GameLift Servers hosting solution for your game server. 

With the plugin, you can build a basic working hosting solution and then optimize and customize as needed. Set up an Amazon GameLift Servers Anywhere fleet with your local workstation as a host. For cloud hosting with managed EC2 or managed container fleets, deploy your game server with a complete solution to manage game session requests and client connections.

**Topics**
+ [Install the plugin for your Unreal game project](#unreal-plugin-install)
+ [Next steps: Customize your game hosting solution](#unreal-plugin-next-steps)
+ [Plugin for Unreal: Set up an AWS user profile](unreal-plugin-profiles.md)
+ [Plugin for Unreal: Integrate your game code](unreal-plugin-integrate.md)
+ [Plugin for Unreal: Host your game locally with Amazon GameLift Servers Anywhere](unreal-plugin-anywhere.md)
+ [Plugin for Unreal: Deploy your game to a managed EC2 fleet](unreal-plugin-ec2.md)
+ [Plugin for Unreal: Deploy your game to a managed container fleet](unreal-plugin-container.md)

## Install the plugin for your Unreal game project
<a name="unreal-plugin-install"></a>

**[ Get the Amazon GameLift Servers plugin for Unreal Engine from GitHub](https://github.com/amazon-gamelift/amazon-gamelift-plugin-unreal)**

See the GitHub repository readme for information about how to install the plugin in your Unreal Editor for a game project. 

The plugin includes these components: 
+ Plugin modules for the UE editor. When the plugin is installed, a new main menu button gives you access to Amazon GameLift Servers functionality.
+ C\$1\$1 libraries for the Amazon GameLift Servers service API. Use API functionality in a client-side backend service to help game clients request game sessions and send/retrieve game session information. 
+ Unreal libraries for the Amazon GameLift Servers server SDK (version 5). Use the server SDK in your game server code to manage communication between hosted game server processes and the Amazon GameLift Servers service.
+ Content for testing, including a startup game map and two testing maps with basic blueprints and UI elements for use with testing a server integration.
+ Editable configurations, in the form of CloudFormation templates, that the plugin uses when deploying your game server for hosting.

This plugin uses AWS CloudFormation templates to deploy hosting solutions for common gaming scenarios. Use these solutions as provided or customize them as needed for your games.

## Next steps: Customize your game hosting solution
<a name="unreal-plugin-next-steps"></a>

Using the plugin's guided workflows is a good way to get up and running fast with an Amazon GameLift Servers hosting solution. With the plugin, you can set up basic versions of each of your solution's components.

When you're ready, you can build on this basic solution by customizing each component, and fine-tuning your solution as you prepare for game launch. Consider these options: 
+ Modify your fleets and fleet configurations. See [Hosting resource customizations](fleets-design.md).
+ Customize your game session queue configuration. See [Customize a game session queue](queues-design.md): 
+ Add functionality to your game server and game client. See [Integrate a game server with Amazon GameLift Servers](gamelift-sdk-server.md) and [Integrate Amazon GameLift Servers game client functionality](gamelift-sdk-client-api.md).
+ Customize your backend service. See [Build a backend service for Amazon GameLift Servers](gamelift_quickstart_customservers_designbackend.md).
+ Set up automatic capacity scaling to meet expected player demand. See [Scaling game hosting capacity with Amazon GameLift Servers](fleets-manage-capacity.md).
+ Set up hosting observability tools, including analytics and logging. See [Monitoring Amazon GameLift Servers](monitoring-overview.md).
+ Automate your deployment using [infrastructure as code (IaC)](https://docs.aws.amazon.com/whitepapers/latest/introduction-devops-aws/infrastructure-as-code.html). The plugin's guided workflows for managed solutions use AWS CloudFormation templates. You can customize these as needed. See [Manage Amazon GameLift Servers hosting resources using CloudFormation](resources-cloudformation.md).

**Topics**
+ [Install the plugin for your Unreal game project](#unreal-plugin-install)
+ [Next steps: Customize your game hosting solution](#unreal-plugin-next-steps)
+ [Plugin for Unreal: Set up an AWS user profile](unreal-plugin-profiles.md)
+ [Plugin for Unreal: Integrate your game code](unreal-plugin-integrate.md)
+ [Plugin for Unreal: Host your game locally with Amazon GameLift Servers Anywhere](unreal-plugin-anywhere.md)
+ [Plugin for Unreal: Deploy your game to a managed EC2 fleet](unreal-plugin-ec2.md)
+ [Plugin for Unreal: Deploy your game to a managed container fleet](unreal-plugin-container.md)

# Plugin for Unreal: Set up an AWS user profile
<a name="unreal-plugin-profiles"></a>

After installing the plugin, set up a user profile with a valid AWS account. You can maintain multiple profiles in the plugin, but you can have only one profile selected at a time. Whenever you work in the plugin, select a profile to use. Each workflow page displays the currently selected profile. 

Maintaining multiple profiles gives you the ability to switch between different hosting deployments. For example, you might set up profiles that use the same AWS account but deploy to different AWS Regions. Or you might set up profiles with different AWS accounts or users and permission sets.

**Note**  
If you've installed the AWS CLI on your workstation and have a profile already configured, the Amazon GameLift Servers plugin will detect it and list it as an existing profile. The plugin automatically selects any profile named `[default]`. You can use an existing profile or create a new one. 

All profiles must be bootstrapped to set up some required AWS resources under your account user.

**To manage your AWS profiles**

1. In the Unreal editor main toolbar, choose the Amazon GameLift Servers menu, and select **AWS Access Credentials**. This action opens the Amazon GameLift Servers plugin to the page **Set up your user profile**.

1. Use the buttons to create a new AWS account or set up a user profile for an AWS account that you already have. 

1. If you don't already have a user profile, you're prompted to enter profile details and create a new profile. Provide the following information:
   + An AWS account. If you create a new AWS account, use the link to the AWS Management Console and follow the prompts. See [ Create an AWS account](https://docs.aws.amazon.com/accounts/latest/reference/manage-acct-creating.html) for more details.
   + An AWS user with permissions to use Amazon GameLift Servers and other required AWS services. See [Set up an AWS user account](setting-up-aws-login.md) for instructions on setting up an AWS Identity and Access Management (IAM) user with Amazon GameLift Servers permissions and programmatic access with long-term credentials.
   + Credentials for your AWS user. These credentials consist of an AWS access key ID and AWS secret key. See [ Get your access keys](https://docs.aws.amazon.com/cli/latest/userguide/cli-authentication-user.html#cli-authentication-user-get) for more details.
   + AWS region. This is a geographic location where you want to create your AWS resources for hosting. During development, we recommend using a region close to your physical location. Choose a region from the list of [ supported AWS regions](https://docs.aws.amazon.com/general/latest/gr/gamelift.html).

1. If the plugin detects existing profiles, it displays a list of available profiles. Select an existing profile from the list, or choose **Add another profile** to create a new one. 

## Bootstrap a user profile
<a name="unreal-plugin-profiles-bootstrap"></a>

All profiles must be bootstrapped to use with the Amazon GameLift Servers plugin. Bootstrapping creates an Amazon S3 bucket specific to the profile. It's used to store project configurations, build artifacts, and other dependencies. Buckets are not shared between other profiles.

Bootstrapping involves creating new AWS resources and might incur costs.

**To bootstrap your profile:**

1. On the **AWS Access Credentials** page, check the bootstrap status of the user profile that you want to use. If the profile's bootstrap status is "Inactive" and there's no S3 bucket listed, you need to bootstrap the profile. 

1. Select the profile you want to use and choose **Bootstrap profile**. 

1. Wait for bootstrap status to change to "Active". This can take a few minutes.

# Plugin for Unreal: Integrate your game code
<a name="unreal-plugin-integrate"></a>

Before you can deploy your game server to a fleet, you need to make a series of updates to game code and package game components for use with the Amazon GameLift Servers service.

This topic walks through the steps for doing a minimal integration. For server integration, use the provided code sample to update your project's game mode. 
+ [Set up build targets and module rules](#unreal-plugin-anywhere-integrate-setup)
+ [Update your game server code](#unreal-plugin-anywhere-integrate-simple-server)
+ [Integrate your client game map](#unreal-plugin-anywhere-integrate-simple-client)
+ [Package your game components](#unreal-plugin-anywhere-integrate-build)

## Set up build targets and module rules
<a name="unreal-plugin-anywhere-integrate-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.

## Update your game server code
<a name="unreal-plugin-anywhere-integrate-simple-server"></a>

Update your game server code to enable communication between a game server process and the Amazon GameLift Servers service. Your game server must be able to respond to requests from Amazon GameLift Servers, such as to start and stop new game sessions.

**To add server code for Amazon GameLift Servers**

1. In your code editor, open the solution (`.sln`) file for your game project, usually found in the project root folder. For example: `GameLiftUnrealApp.sln`.

1. With the solution open, locate the project game mode header file: `[project-name]GameMode.h` file. For example: `GameLiftUnrealAppGameMode.h`. 

1. Change the header file to align with the following code. Be sure to replace "GameLiftServer" with your own project name. These updates are specific to the game server; we recommend that you make a backup copy of the original game mode files for use with your client.

### Example gameMode.h code
<a name="w2aab9c11b9c19c27c11b7b1"></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;
};
```
+ Open the related source file `[project-name]GameMode.cpp` file (for example `GameLiftUnrealAppGameMode.cpp`). Change the code to align with the following example code. Be sure to replace "GameLiftUnrealApp" with your own project name. These updates are specific to the game server; we recommend that you make a backup copy of the original file for use with your client.

  The following example code shows how to add the minimum required elements for server integration with Amazon GameLift Servers:
  + Initialize an Amazon GameLift Servers API client. The `InitSDK()` call with server parameters is required for an Amazon GameLift Servers Anywhere fleet. When you connect to an Anywhere fleet, the plugin stores the server parameters as console arguments The sample code can access the values at runtime. 
  + Implement required 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 ready to host game sessions.

### Example game server code
<a name="w2aab9c11b9c19c27c11c11b1"></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 shutdown.
    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
}
```

## Integrate your client game map
<a name="unreal-plugin-anywhere-integrate-simple-client"></a>

The startup game map contains blueprint logic and UI elements that already include basic code to request game sessions and use connection information to connect to a game session. You can use the map as is or modify these as needed. Use the startup game map with other game assets, such as the Third Person template project provided by Unreal Engine. These assets are available in Content Browser. You can use them to test the plugin's deployment workflows, or as a guide to create a custom backend service for your game.

The startup map has the following characteristics: 
+ It includes logic for both an Anywhere fleet and a managed EC2 fleet. When you run your client, you can choose to connect to either fleet.
+ Client functionality includes find a game session (`SearchGameSessions()`), create a new game session (`CreateGameSession()`), and join a game session directly.
+ It gets a unique player ID from your project's Amazon Cognito user pool (this is part of a deployed Anywhere solution). 

**To use the startup game map**

1. In the UE editor, open the **Project Settings, Maps & Modes** page, and expand the **Default Maps** section.

1. For **Editor Startup Map**, select "StartupMap" from the dropdown list. You might need to search for the file, which is located in `... > Unreal Projects/[project-name]/Plugins/Amazon GameLift Servers Plugin Content/Maps`.

1. For **Game Default Map**, select the same "StartupMap" from the dropdown list.

1. For **Server Default Map**, select "Lv1\$1ThirdPerson" for Unreal Engine 5.6 or later, or "ThirdPersonMap" for earlier versions. This is a default map included in your game project. This map is designed for two players in the game.

1. Open the details panel for the server default map. Set **GameMode Override** to "None".

1. Expand the **Default Modes** section, and set **Global Default Server Game Mode** to the game mode you updated for your server integration. 

After you've made these changes to your project, you're ready to build your game components.

**Note**  
For Unreal Engine 5.6 or later, if you cannot move the character after connecting to the game server, update the BP\$1ThirdPersonCharacter blueprint to add input mapping context for `IMC_Default` and `IMC_MouseLook` as shown below:  

![\[alt text not found\]](http://docs.aws.amazon.com/gameliftservers/latest/developerguide/images/unreal-enhanced-input-blueprint.png)


## Package your game components
<a name="unreal-plugin-anywhere-integrate-build"></a>

**To package your game server and game client builds**

1. Open your game project in a source-built version of the Unreal Engine editor.

1. If using Unreal Engine 5.6 or later, go to **Edit, Project Settings, Packaging**. Find **Cook everything in the project content directory** and enable it.

1. Use the editor to package your game client and server builds. 

   1. Choose a target. Go to **Platforms, Windows** and select one of the following:
      + Server: `[your-application-name]Server`
      + Client: `[your-application-name]Client`

   1. Start the build. Go to **Platform, Windows, Package Project**.

Each packaging process generates an executable: `[your-application-name]Client.exe` or `[your-application-name]Server.exe`.

In the plugin, set the paths to the client and server build executables on your local workstation.

# Plugin for Unreal: Host your game locally with Amazon GameLift Servers Anywhere
<a name="unreal-plugin-anywhere"></a>

Use this workflow to set up your local workstation as a game server host using an Anywhere fleet. You can use it to test your game server integration before deploying to a cloud-based managed fleet. It can also be useful for local testing during iterative game development.

**To start the Amazon GameLift Servers Anywhere workflow:**
+ In the Unreal editor main toolbar, choose the Amazon GameLift Servers menu, and select **Host with Anywhere**. This action opens the plugin page **Deploy Anywhere**, which presents a six-step process to integrate, build, and launch your game components. 

## Step 1: Set your profile
<a name="unreal-plugin-anywhere-profile"></a>

Choose the profile you want to use when following this workflow. The profile you select impacts all steps in the workflow. All resources you create are associated with the profile's AWS account and are placed in the profile's default AWS Region. The profile user's permissions determine your access to AWS resources and actions.

**To set a user profile**

1. Select a profile from the dropdown list of available profiles. If you don't have a profile yet or want to create a new one, go to the **Amazon GameLift** menu and choose **Set AWS User Profiles**.

1. If bootstrap status is not "Active", choose **Bootstrap profile** and wait for the status to change to "Active".

## Step 2: Set up your game code
<a name="unreal-plugin-anywhere-integrate"></a>

In this step, prepare your game server and game client builds to work with Amazon GameLift Servers. If you haven't yet integrated your game code, see [Plugin for Unreal: Integrate your game code](unreal-plugin-integrate.md). Enter the paths to your game executables on your local workstation.
+ Game server: Integrate your game server with the server SDK for Amazon GameLift Servers and package your game server build. For instructions, see [Plugin for Unreal: Integrate your game code](unreal-plugin-integrate.md). The game server must be integrated with the server SDK in order to establish communication with the Amazon GameLift Servers service and respond to prompts to start new game sessions and accept game client connections.
+ Game client: At minimum, you need a game client that can connect to your game server using IP address and port information. If you don't yet have your game client components set up for Amazon GameLift Servers, you can use the AWS CLI tool to manually request new game sessions, get connection information, and use that information to connect the game client. 

  At some point, you'll need to have a backend service to send new game sessions requests to the Amazon GameLift Servers service and relay connection information back to a game client. You can use the test maps included with the plugin to add client Amazon GameLift Servers functionality to your game project. For help with building a custom solution, see [Integrate Amazon GameLift Servers game client functionality](gamelift-sdk-client-api.md).

## Step 3: Connect to an Anywhere fleet
<a name="unreal-plugin-anywhere-fleet"></a>

In this step, you designate an Anywhere fleet to use. An Anywhere fleet defines a collection of compute resources, which can be located anywhere, for game server hosting.
+ If the AWS account you're currently using has existing Anywhere fleets, open the Fleet name dropdown field and choose a fleet. This dropdown only shows the Anywhere fleets in the AWS Region for the currently active user profile.
+ If there are no existing fleets—or you want to create a new one, choose Create new Anywhere fleet and provide a fleet name.

After you've chosen an Anywhere fleet for your project, Amazon GameLift Servers verifies that fleet status is active and displays the fleet ID. You can track progress of this request in the Unreal editor's output log.

## Step 4: Register your workstation
<a name="unreal-plugin-anywhere-register"></a>

In this step, you register your local workstation as a compute resource in the new Anywhere fleet.

**To register your workstation as an Anywhere compute**

1. Enter a compute name for your local machine. If you add more than one compute in the fleet, the names must be unique.

1. Provide an IP address for your local machine. This field defaults to your machine's public IP address. You can also use localhost (127.0.0.1) as long as you're running your game client and server on the same machine.

1. Choose Register compute. You can track progress of this request in the Unreal editor's output log.

In response to this action, Amazon GameLift Servers verifies that it can connect to the compute and returns information about the newly registered compute. It also creates the console arguments that your game executables need when initializing communication with the Amazon GameLift Servers service. 

## Step 5: Generate auth token
<a name="unreal-plugin-anywhere-auth"></a>

Game server processes that are running on your Anywhere compute need an authentication token to make calls to the Amazon GameLift Servers service. The plugin automatically generates and stores an auth token for the Anywhere fleet whenever you launch the game server from the plugin. The auth token value is stored as a command line argument, which your server code can retrieve at runtime.

The code examples given above also allow you to use [AWS Signature Version 4 (SigV4) for API requests](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_sigv.html). SigV4 is the AWS signing protocol for adding authentication information to API requests.

You do not have to take any action in this step.

## Step 6: Launch game
<a name="unreal-plugin-anywhere-launch"></a>

At this point, you've completed all of the tasks needed to launch and play your multiplayer game on a local workstation using Amazon GameLift Servers. 

**To play your hosted game**

1. Launch your game server. The game server will notify Amazon GameLift Servers when it is ready to host game sessions.

1. Launch your game client and use the new functionality to start a new game session. This request is sent to Amazon GameLift Servers via the new backend service. In response, Amazon GameLift Servers, calls the game server, running on your local machine, to start a new game session. When the game session is ready to accept players, Amazon GameLift Servers provides connection information for the game client to join the game session.

# Plugin for Unreal: Deploy your game to a managed EC2 fleet
<a name="unreal-plugin-ec2"></a>

In this workflow, deploy your game for hosting on cloud-based compute resources managed by Amazon GameLift Servers. Upload your integrated game server build to the Amazon GameLift Servers service for deployment. If you haven't yet integrated your game code, see [Plugin for Unreal: Integrate your game code](unreal-plugin-integrate.md). When this workflow is complete, you'll have a working game client that can connect to your game servers in the cloud. 

**To start the Amazon GameLift Servers managed Amazon EC2 workflow:**
+ In the Unreal editor main toolbar, choose the Amazon GameLift Servers menu, and select **Host with Managed EC2**. This action opens the plugin page **Deploy Amazon EC2 Fleet**, which presents a six-step process to integrate, build, deploy, and launch your game components. 

## Step 1: Set your profile
<a name="unreal-plugin-ec2-profile"></a>

Choose the profile you want to use when following this workflow. The profile you select impacts all steps in the workflow. All resources you create are associated with the profile's AWS account and are placed in the profile's default AWS Region. The profile user's permissions determine your access to AWS resources and actions.

**To set a user profile**

1. Select a profile from the dropdown list of available profiles. If you don't have a profile yet or want to create a new one, go to the **Amazon GameLift** menu and choose **Set AWS User Profiles**.

1. If bootstrap status is not "Active", choose **Bootstrap profile** and wait for the status to change to "Active".

## Step 2: Set up your game code
<a name="unreal-plugin-ec2-integrate"></a>

In this step, prepare your game server and game client builds to work with Amazon GameLift Servers C\$1\$1 server SDK for Unreal. If you haven't yet integrated your game code and built game client and server executables, see [Plugin for Unreal: Integrate your game code](unreal-plugin-integrate.md). Enter the paths to your game executables on your local workstation.

This step in the workflow the plugin provides links to instructions and source code for setting up a source-built version of the Unreal Editor. You need to use the source-built version when building your client and server components.

After building game server that's integrated with the server SDK, complete the following tasks to prepare it for uploading to Amazon GameLift Servers for hosting.

### To prepare your server build for cloud deployment (Windows)
<a name="w2aab9c11b9c19c35b9b9b1"></a>

In the `WindowsServer` folder, where the Unreal editor stores your server build files by default, make the following additions:

1. **Copy the server build install script into the root of the `WindowsServer` folder.** The install script is included in the plugin download. Look for the file `[project-name]/Plugins/Resources/CloudFormation/extra_server_resources/install.bat`. Amazon GameLift Servers uses this file to install the server build onto your hosting computes.

1. **Copy the `VC_redist.x64.exe` file into the root of the `WindowsServer` folder.** You can skip this step if you're using Unreal Engine version 5.6 or later. This file is included in your Visual Studio installation. It is commonly located at `C:/Program Files (x86)/Microsoft Visual Studio/2019/Professional/VC/Redist/MSVC/v142`.

1. **Add the OpenSSL library files to your game server build.**. You can skip this step if your game server is integrated with server SDK 5.3 or later. This version is included in the Amazon GameLift Servers plugin for Unreal, version 3.0 or later. 

   Manually locate and copy the OpenSSL libraries to your game build package directory at `<YourGame>/Binaries/Win64`. You **must** use the same OpenSSL version that your Unreal Engine 5 version uses. Game builds that are deployed with the wrong OpenSSL libraries won't be able to communicate with the Amazon GameLift Servers service.

   Look for the OpenSSL libraries 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`

### To prepare your server build for cloud deployment (Linux)
<a name="w2aab9c11b9c19c35b9c11b1"></a>

For more detailed instructions on preparing a game server built for Linux, see [ Building the server SDK for Amazon GameLift Servers for Unreal Engine 5 on Amazon Linux](https://github.com/aws/amazon-gamelift-toolkit/tree/main/building-gamelift-server-sdk-for-unreal-engine-and-amazon-linux).

1. **Designate a working directory to organize your build files.** The working directory's structure is deployed as is onto each hosting compute. Add your Linux-built game server and all dependent files. 

1. **Create a server build install script in the root of your working directory.** If needed,create an `install.sh` file and add any commands needed to properly install your game server build. Amazon GameLift Servers uses this file to install the server build onto each EC2 hosting resource.

1. **Add the OpenSSL library files to your game server build.** You can skip this step if your game server is integrated with server SDK 5.3 or later. 

   Manually locate and copy the libraries. You **must** use the same OpenSSL version that your Unreal Engine 5 version uses. Game builds that are deployed with the wrong OpenSSL libraries won't be able to communicate with the Amazon GameLift Servers service.

   1. Look for the OpenSSL libraries 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`

   1. When you locate the OpenSSL libraries, copy them to your game build package directory at `<YourGame>/Binaries/Linux`. 

## Step 3: Select deployment scenario
<a name="unreal-plugin-ec2-scenarios"></a>

In this step, you choose the game hosting solution that you want to deploy at this time. You can have multiple deployments of your game, using any of the scenarios. 
+ Single-region fleet: Deploys your game server to a single fleet of hosting resources in the active profile's default AWS region. This scenario is a good starting point for testing your server integration with AWS and server build configuration. It deploys the following resources:
  + AWS fleet (On-Demand) with your game server build installed and running.
  + Amazon Cognito user pool and client to enable players to authenticate and start a game.
  + API gateway authorizer that links user pool with APIs.
  + WebACl for throttling excessive player calls to API gateway.
  + API gateway \$1 Lambda function for players to request a game slot. This function calls `CreateGameSession()` if none are available.
  + API gateway \$1 Lambda function for players to get connection info for their game request.
+ FlexMatch fleet: Deploys your game server to a set of fleets and sets up a FlexMatch matchmaker with rules to create player matches. This scenario uses low-cost Spot hosting with a multi-fleet, multi-location structure for durable availability. This approach is useful when you're ready to start designing a matchmaker component for your hosting solution. In this scenario, you'll create the basic resources for this solution, which you can customize later as needed. It deploys the following resources:
  + FlexMatch matchmaking configuration and matchmaking rule set to accept player requests and form matches.
  + Three AWS fleets with your game server build installed and running in multiple locations. Includes two Spot fleets and one On-Demand fleet as a backup. 
  + AWS game session placement queue that fulfills requests for proposed matches by finding the best possible hosting resource (based on viability, cost, player latency, etc.) and starting a game session.
  + Amazon Cognito user pool and client to enable players to authenticate and start a game.
  + API gateway authorizer that links user pool with APIs.
  + WebACl for throttling excessive player calls to API gateway.
  + API gateway \$1 Lambda function for players to request a game slot. This function calls `StartMatchmaking()`.
  + API gateway \$1 Lambda function for players to get connection info for their game request.
  + Amazon DynamoDB tables to store matchmaking tickets for players and game session information.
  + SNS topic \$1 Lambda function to handle GameSessionQueue events.

## Step 4: Set game parameters
<a name="unreal-plugin-ec2-parameters"></a>

In this step, you describe your game for uploading to AWS;
+ Server build name: Provide a meaningful name for your game server build. AWS uses this name to refer to the copy of your server build that's uploaded and used for deployments.
+ Server build OS: Enter the operating system that your server is built to run on. This tells AWS what type of compute resources to use to host your game.
+ Game server folder: Identify the path to your local server build folder.
+ Game server build: Identify the path to the game server executable.
+ Game client path: Identify the path to the game client executable.
+ Client configuration output: This field needs to point to a folder in your client build that contains your AWS configuration. Look for it in the following location: `[client-build]/[project-name]/Content/CloudFormation`. 

## Step 5: Deploy scenario
<a name="unreal-plugin-ec2-deploy"></a>

In this step, you deploy your game to a cloud hosting solution based on the deployment scenario you chose. This process can take several minutes while AWS validates your server build, provisions hosting resources, installs your game server, launches server processes, and gets them ready to host game sessions.

To start deployment, choose **Deploy CloudFormation**. You can track the status of your game hosting here. For more detailed information, you can sign in to the AWS Management console for AWS and view event notifications. Be sure to sign in using the same account, user, and AWS Region as the active user profile in the plugin.

When deployment is complete, you have your game server installed on an AWS EC2 instance. At least one server process is running and ready to start a game session. 

## Step 6: Launch client
<a name="unreal-plugin-ec2-launch"></a>

At this point, you've completed all of the tasks needed to launch and play your multiplayer game hosted with Amazon GameLift Servers. To play the game, launch an instance of your game client. 

If you deployed the single fleet scenario, you can open a single client instance with one player, enter the server map and move around. Open additional instances of the game client to add a second player to the same server game map. 

If you deployed the FlexMatch scenario, the solution waits for at least two clients to be queued for game session placement before the players can enter the server map.

# Plugin for Unreal: Deploy your game to a managed container fleet
<a name="unreal-plugin-container"></a>

Use this guided plugin workflow to create a container image for your game server and deploy it to a container-based hosting solution. If you haven't yet integrated your game code, see [Plugin for Unreal: Integrate your game code](unreal-plugin-integrate.md). When you’ve successfully completed this workflow, your containerized game server is running in the cloud, and you can use the plugin to start a game client, connect to a game session, and play the game.

## Before you start
<a name="unreal-plugin-container-prereqs"></a>

This workflow assumes that you’ve completed the following tasks. 
+ **Integrate your game server code with Amazon GameLift Servers server SDK.** Your hosted game server must be able to communicate with the Amazon GameLift Servers service so that it can respond to requests to start new game sessions and report game session status. If you haven’t completed this task, we recommend that you follow the plugin workflow Host with Anywhere first. For guidance on preparing your game server code, see [Update your game server code](unreal-plugin-integrate.md#unreal-plugin-anywhere-integrate-simple-server). For a managed container fleet, you must integrate your game with server SDK version 5.2 or higher.
**Note**  
If you're using the startup game map, this task is already done for you. 
+ **Package your game server executable to run on Linux.** If you’re developing on Windows and integrating C\$1\$1 server SDK version 5.2.x or earlier, you’ll need to work with the [ Unreal cross compile toolkit](http://cross-compile toolkit for your UE version). Alternatively, you might set up a separate Linux workspace or use a tool such as Windows subsystem for Linux (WSL). 
+ **Gather files to deploy with your game server build.** On your local machine, create a working directory to organize the files, which will be built into your game server container image. These might include game dependencies, a script to launch game servers and other processes when starting a container, etc. 
+ **Add the OpenSSL library files for your game server build.** You can skip this step if your game server is integrated with server SDK 5.3 or later. 

  Manually locate and copy the OpenSSL libraries to your game build package directory at `<YourGame>/Binaries/Win64`. You **must** use the same OpenSSL version that your Unreal Engine 5 version uses. Game builds that are deployed with the wrong OpenSSL libraries won't be able to communicate with the Amazon GameLift Servers service.

  To find the OpenSSL libraries, look 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`
+ **Integrate your game client code with Amazon GameLift Servers.** One way to complete this task is to add a sample asset (included with the plugin) that’s already integrated. For guidance on preparing your game client code, see [Integrate your client game map](unreal-plugin-integrate.md#unreal-plugin-anywhere-integrate-simple-client). 
+ **Install Docker on your local machine.** You need this tool installed if you want the plugin to create container images for you and push them to an ECR repository. Alternatively you can do these tasks manually and instruct the plugin to use an existing container image. For more information about building your image manually, see [ Build a container image for Amazon GameLift Servers](https://docs.aws.amazon.com/gameliftservers/latest/developerguide/containers-prepare-images.html).

**To start the Amazon GameLift Servers managed containers workflow:**
+ In the Unreal editor main toolbar, choose the Amazon GameLift Servers menu, and select **Managed Containers**. This action opens the plugin page **Host with Managed Containers**, which presents a step-by-step process to create a container image with your game server build, deploy it to a container fleet, and launch your game. 

## Step 0: Set your profile
<a name="unreal-plugin-container-profile"></a>

This section displays your currently selected user profile. Verify that the current user profile is the one you want to use for this workflow. All the resources that you create in this workflow are associated with the profile's AWS account and are placed in the profile's default AWS Region. The profile user's permissions determine your access to AWS resources and actions.

You might need to modify the selected user profile if: 
+ No profile is currently selected.
+ You want to select a different profile or create a new profile.
+ You need to bootstrap the selected profile (if bootstrap status is inactive).

**To set or change the selected user profile**
+ In the Amazon GameLift Servers menu, choose **Open AWS Access Credentials**.

## Step 1: Assess container readiness
<a name="unreal-plugin-container-assess"></a>

Before deploying your game server to a container fleet, you must package it into a container image and store in an Amazon ECR repository. The plugin can complete these tasks for you or you can do these tasks manually. In this step, provide information about the status of your container image and the ECR repository. 

Use the assessment questions to tell the plugin what steps it needs to take: 
+ **Create a new container image.** If you choose this option, the next step will prompt you for the location of your game server build directory and the build executable. The plugin uses a Dockerfile template (supplied by Amazon GameLift Servers) and automatically configures it for your game. You can view the template at [Build a container image for Amazon GameLift Servers](containers-prepare-images.md). After choosing this option, indicate where you want the plugin to store the new image:
  + Create a new Amazon ECR repository and push the container image to it. The plugin creates a private ECR repo using the AWS account and default AWS Region in your selected user profile.
  + Push the container image to a previously created Amazon ECR repository. If you choose this option, the next step will prompt you to select an existing Amazon ECR repository from a list. The list includes all Amazon ECR repositories for the AWS account and default AWS Region in your selected user profile. You can select a public or private repository.
+ **Use an existing container image.** If you've manually built an image, we recommend that you use the Dockerfile template supplied by Amazon GameLift Servers, which is available at [Build a container image for Amazon GameLift Servers](containers-prepare-images.md). After choosing this option, indicate where the image is located. 
  + A locally stored Docker-generated image. If you choose this option, the plugin creates a new Amazon ECR private repository and pushes the local image file to it. The next step will prompt you for an image ID, which the plugin uses to locate the image file.
  + A container image that's already stored in an Amazon ECR repository. If you choose this option, the next step will prompt you to select an existing Amazon ECR repository and image from a list. The list includes all Amazon ECR repositories for the AWS account and default AWS Region in your selected user profile. You can select a public or private repository.

## Step 2: Configure image deployment
<a name="unreal-plugin-container-configure"></a>

In this step, provide information that the plugin needs to deploy your container image to a container fleet. This step requests the following information: 
+ The location of your game server build, container image, or Amazon ECR repository, based on your selections in Step 1. 
+ The scenario to use for your managed containers deployment.
+ The client configuration output path. Select the folder in your client build that contains your AWS configuration. Look for it in the following location: `[client-build]/[project-name]/Content/CloudFormation`. 
+ Optional deployment settings. This section has configuration settings that the plugin uses by default. You can modify these or keep the default values
  + Game name is set to the name of your game project by default. All AWS resources that the plugin creates references the game name value.
  + Port range, memory limit, and vCPU limit are configuration settings for the container fleet. For more information about customizing these values, see [Configure network connections](containers-design-fleet.md#containers-custom-network) for connection port range, and [Set resource limits](containers-design-fleet.md#containers-design-fleet-limits) for resource limits.
  + Container image tag is used to categorize your container images in Amazon ECR. The default value is `unreal-gamelift-plugin`.
  + Name of the Amazon ECR repository. You can edit this field to suggest a custom name only when the plugin is creating an ECR repository for you. The default value is `unreal-game lift-plugin-ecr-repository`.

### Deployment scenario options
<a name="unreal-plugin-container-configure-scenarios"></a>

#### Single-region container fleet
<a name="w2aab9c11b9c19c39c13b7b3b1"></a>

This scenario deploys your game server to a single container fleet. It's a good starting point for testing your server integration with AWS and your container configuration. It deploys the following resources. 
+ Amazon GameLift Servers container group definition describes how to deploy and run your container images on a container fleet. 
+ Amazon GameLift Servers container fleet (On-Demand) with your game server container installed and running, with alias.
+ Amazon Cognito user pool and client to enable players to authenticate and start a game.
+ API Gateway authorizer that links the user pool with APIs.
+ Web access control list (ACL) for throttling excessive player calls to API Gateway.
+ Backend service to make requests to the Amazon GameLift Servers service on behalf of game clients, such as to request game sessions and join games: 
  + API Gateway \$1 Lambda function for players to request a game session slot. This function calls `CreateGameSession()` if no open slots are available.
  + API Gateway \$1 Lambda function for players to get connection info for their game request.

#### Single-region container fleet with FlexMatch
<a name="w2aab9c11b9c19c39c13b7b3b3"></a>

This scenario deploys your game server to a container fleet, configures game session placement, and sets up FlexMatch matchmaking. This scenario is useful when you're ready to start designing a custom matchmaker for your hosting solution. Use this scenario to create the basic resources for this solution, which you can customize later as needed. It deploys the following resources:
+ Amazon GameLift Servers container group definition that describes how to deploy and run your container images on a container fleet. 
+ Amazon GameLift Servers container fleet (On-Demand) with your game server container installed and running, with alias.
+ FlexMatch matchmaking configuration and matchmaking rule set to accept player requests and form matches.
+ Amazon GameLift Servers game session queue that fulfills requests for proposed matches by finding the best possible hosting resource (based on viability, cost, player latency, etc.) and starting a game session.
+ Amazon Cognito user pool and client to enable players to authenticate and start a game.
+ API Gateway authorizer that links the user pool with APIs.
+ Web access control list (ACL) for throttling excessive player calls to API Gateway.
+ Backend service to make requests to the Amazon GameLift Servers service on behalf of game clients, such as to request game sessions and join games: 
  + API Gateway \$1 Lambda function for players to request a game session slot. This function calls `StartMatchmaking()` if no open slots are available.
  + API Gateway \$1 Lambda function for players to get connection info for their game request.
+ DynamoDB tables to store matchmaking tickets for players and game session information.
+ Amazon SNS topic \$1 Lambda function to handle GameSessionQueue events.

## Deploy container fleet
<a name="unreal-plugin-container-deploy"></a>

When your fleet configuration is complete, choose the **Deploy container fleet** button to start deployment. This process can take several minutes while the plugin creates a container image and pushes it to ECR, provisions hosting resources for the container fleet, deploys the fleet and other AWS resources for the selected hosting solution scenario. 

When you start a deployment, you can track the progress of each step. Depending on your configuration, the steps might include the following: 
+ Configuring container image
+ Creating an Amazon ECR repository 
+ Building an image and pushing to Amazon ECR
+ Creating container group definition
+ Creating container fleet

For more detailed deployment information, choose **View in AWS Management Console**. When the container fleet reaches active status, the fleet is actively running containers with server processes that are ready to host game sessions.

When deployment is complete, you have a working container fleet that’s ready to host game sessions and accept player connections. 

You can’t stop a deployment in progress. If the deployment enters a bad state or fails, you can start over by using the **Reset deployment** option.

## Launch client
<a name="unreal-plugin-container-launch"></a>

At this point, you've completed all the tasks to launch and play your multiplayer game hosted with Amazon GameLift Servers. To play your game, choose **Start Client** to launch a local instance of your game client. 
+ If you deployed the single fleet scenario, open one instance of your game client with one player and enter the server map to move around. You can open a second instance of the game client to add a second player to the same server game map.
+ If you deployed the FlexMatch scenario, the hosting solution waits for at least two game clients to make matchmaking requests. Open at least two instances of your game client with one player. The two players will be matched and prompted to join a game session for the match. 

## Update a container fleet
<a name="unreal-plugin-container-update"></a>

If you've successfully deployed a managed containers hosting solution, you can use the **Update deployment**feature. This option lets you update configuration settings for a deployed container fleet, without having to create a new fleet. 

When updating a deployment, you can deploy a container image with a different game server build, change the Amazon ECR repository, choose a different deployment scenario, and customize optional configuration settings.

When you're ready to deploy your changes, choose Update. The time required for a deployment update is similar to a full deployment. For detailed deployment information, choose **View in AWS Management Console**.

## Clean up deployed resources
<a name="unreal-plugin-container-cleanup"></a>

As a best practice, clean up the AWS resources for your managed containers solution as soon as you no longer need them. You might continue to incur costs for these resources if you don't remove them.

Delete the following resources:
+ Managed container resource stack. The resources in this stack depends on the deployment scenario you selected. To delete the entire stack, use the CloudFormation console. Stacks that are generated from the Amazon GameLift Servers plugin use the following naming convention: `GameLiftPluginForUnreal-{GameName}-Containers`. Wait for the stack deletion process to complete before you initiate a new managed containers deployment in the plugin. For more information, see [ Delete a stack from the CloudFormation console](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/cfn-console-delete-stack.html).
+ Amazon ECR repository. If you used the plugin to create a repository for your container image, you might want to delete any repositories that are no longer needed. You don't need to delete a repository before resetting a managed containers deployment. If you update or reset a deployment, the plugin will automatically use the same repository unless directed to use another one. For more information, see [ Deleting a private repository in Amazon ECR](https://docs.aws.amazon.com/AmazonECR/latest/userguide/repository-delete.html).