Menu
Amazon GameLift
Developer Guide (Version )

Add Amazon GameLift to an Unreal Engine Game Server Project

This topic helps you set up and use the Amazon GameLift Server SDK plugin for Unreal Engine in your game server projects. If you're unsure whether Amazon GameLift supports the operating systems you're using, see For Game Servers.

Set Up the Unreal Engine Server SDK Plugin

Follow these steps to get the Amazon GameLift Server SDK plugin for Unreal Engine ready for your game server projects.

To set up the Amazon GameLift SDK plugin for Unreal Engine

  1. Download the Amazon GameLift Server SDK.

  2. Build the C++ SDK for Unreal. The download contains the source code for the SDK. To create the Unreal version of the SDK libraries, compile the source and set the flag -DBUILD_FOR_UNREAL to true. For more details on building the C++ SDK, including minimal requirements and additional build options, see the C++ SDK README.md file in the download.

    In Linux do the following:

    Copy
    mkdir out cd out cmake -DBUILD_FOR_UNREAL=1 .. make

    The following binary files are generated:

    • out/prefix/lib/aws-cpp-sdk-gamelift-server.so

    In Windows do the following:

    Copy
    mkdir out cd out cmake -G "Visual Studio 14 2015 Win64" -DBUILD_FOR_UNREAL=1 .. msbuild ALL_BUILD.vcxproj /p:Configuration=Release

    The following binary files are generated:

    • out\prefix\bin\aws-cpp-sdk-gamelift-server.dll

    • out\prefix\lib\aws-cpp-sdk-gamelift-server.lib

  3. Add the binaries to the Amazon GameLift plugin files. Copy the new binary files into the ThirdParty directory of the Unreal plugin, with the following paths:

    In Linux use these paths:

    • ThirdParty/GameLiftServerSDK/Linux/x86_64-unknown-linux-gnu/aws-cpp-sdk-gamelift-server.so

    In Windows use these paths:

    • ThirdParty\GameLiftServerSDK\Win64\aws-cpp-sdk-gamelift-server.dll

    • ThirdParty\GameLiftServerSDK\Win64\aws-cpp-sdk-gamelift-server.lib

  4. Import the Amazon GameLift plugin into a project. Although you have many ways to import a plugin into Unreal Engine, the following method does not require the Unreal Editor.

    1. Add the plugin to your game project. The plugin files must contain everything in the plugin's GameLiftServerSDK directory, including the generated binary files.

    2. Add the plugin to your game's .uproject file:

      Copy
      "Plugins": [ { "Name": "GameLiftServerSDK", "Enabled": true } ]
    3. Add the plugin as a dependency to your game's ModuleRules:

      Copy
      using UnrealBuildTool; public class MyAwesomeGame : ModuleRules { public MyAwesomeGame(TargetInfo Target) { PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore", "GameLiftServerSDK" }); } }

Add Amazon GameLift Code

See the Amazon GameLift Server API Reference for Unreal Engine

When adding Amazon GameLift-specific code to your game project, enclose the code using the preprocessor flag WITH_GAMELIFT=1. This flag ensures that only server builds invoke the Amazon GameLift backplane API and allows you to write code that is executed correctly regardless of the build target type you might produce with it.

Code enclosed with the WITH_GAMELIFT=1 flag is only processed if the following are true:

  • The plugin found the Amazon GameLiftserver SDK binary files.

  • The build is a game server: Target.Type == TargetRules.TargetType.Server

The following code sample provides a simplified example of how to initialize an Unreal Engine game server with Amazon GameLift.

Copy
#include "GameLiftFPS.h" #include "Engine.h" #include "EngineGlobals.h" #include "GameLiftFPSGameMode.h" #include "GameLiftFPSHUD.h" #include "GameLiftFPSCharacter.h" #include "GameLiftServerSDK.h" AGameLiftFPSGameMode::AGameLiftFPSGameMode() : Super() { //Let's run this code only if GAMELIFT is enabled. Only with Server targets! #if WITH_GAMELIFT //Getting the module first. FGameLiftServerSDKModule* gameLiftSdkModule = &FModuleManager::LoadModuleChecked<FGameLiftServerSDKModule>(FName("GameLiftServerSDK")); //InitSDK establishes a local connection with GameLift's agent to enable further communication. gameLiftSdkModule->InitSDK(); //When a game session is created, GameLift 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() auto onGameSession = [=](Aws::GameLift::Server::Model::GameSession gameSession) { gameLiftSdkModule->ActivateGameSession(); }; FProcessParameters* params = new FProcessParameters(); params->OnStartGameSession.BindLambda(onGameSession); //OnProcessTerminate callback. GameLift invokes 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 GameLift we are indeed going to shutdown. params->OnTerminate.BindLambda([=](){gameLiftSdkModule->ProcessEnding();}); //This is the HealthCheck callback. //GameLift invokes 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. GameLift defaults to 'false' if the game server doesn't respond in time. //In this case, we're always healthy! params->OnHealthCheck.BindLambda([](){return true; }); //This game server tells GameLift that it listens on port 7777 for incoming player connections. params->port = 7777; //Here, the game server tells GameLift what set of files to upload when the game session ends. //GameLift uploads everything specified here for the developers to fetch later. TArray<FString> logfiles; logfiles.Add(TEXT("aLogFile.txt")); params->logParameters = logfiles; //Calling ProcessReady tells GameLift this game server is ready to receive incoming game sessions! gameLiftSdkModule->ProcessReady(*params); #endif }