I recently got hired by a company that had me implement GameLift into their UE4 project. Since there's not much useful information out there on this in my opinion I figured I'd write up a guide on using it.
Prerequisites for either platform
Building the GameLiftServerSDK for Windows
Prerequisites
- Visual Studio
- cmake (When installing make sure to enable the add to PATH setting)
- Head over to the download page and download the Amazon GameLift Server SDK.
- Unzip the SDK zip file then open Command Prompt into that folder.
- Run
cmake -G "Visual Studio 16 2019" -DBUILD_FOR_UNREAL=1
. - After cmake is finished then run
msbuild ALL_BUILD.vcxproj /p:Configuration=Release
. If msbuild isn't a recognized command then you need to add it to the PATH (environment variable). Or you can open the solution (GameLiftServerSdk.sln) and build that way. If you get some errors about version then you need to edit the file inthirdparty/boost/project-config.jam
and replaceusing msvc ;
withusing msvc : 16.0 ;
the rerun the cmake command. - Go into the
GameLift-SDK-Release-x.x.x/GameLift-Unreal-plugin-x.x.x/UE4.x.x
and copy the GameLiftServerSDK folder to your project's Plugins directory.
- Copy GameLift-SDK-Release-x.x.x/GameLift-Cpp-ServerSDK-x.x.x/prefix/bin/aws-cpp-sdk-gamelift-server.dll and GameLift-SDK-Release-x.x.x/GameLift-Cpp-ServerSDK-x.x.x/prefix/lib/aws-cpp-sdk-gamelift-server.lib to YourProject/Plugins/GameLiftServerSDK/ThirdParty/GameLiftServerSDK/Win64/.
Building the GameLiftServerSDK for Linux
Prerequisites
- Head over to the download page and download the Amazon GameLift Server SDK.
- Unzip the SDK zip file then
cd
into folder.
I used my local storage server (CentOS 7) as I didn't have a vm that was CentOS. /shrug - Any Linux OS should be fine, I just chose CentOS 7. - Run
cmake -DBUILD_FOR_UNREAL=1
then runmake
. (This will take some time to go get a coffee, tea, water, or whatever you like to drink.)
- Go into prefix/lib and copy the libaws-cpp-sdk-gamelift-server.so to YourProject/Plugins/GameLiftServerSDK/ThirdParty/GameLiftServerSDK/Linux/x86_64-unknown-linux-gnu
Adding GameLift to Your Project
- Enable the GameLiftServerSDK plugin in your Editor.
- In YourProject.Build.cs add
GameLiftServerSDK
to the PublicDependencyModuleNames. - In your GameMode class add the following to your constructor. (Code from AWS) Remember to add to your GameMode
#include "GameLiftServerSDK.h".
#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 communication. gameLiftSdkModule->InitSDK(); //Respond to new game session activation request. GameLift sends activation request //to the game server along with a game session object containing game properties //and other settings. Once the game server is ready to receive player connections, //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 before shutting down the instance //that is hosting this game server to give it time to gracefully shut down on its own. //In this example, we simply tell GameLift we are indeed going to shut down. params->OnTerminate.BindLambda([=](){gameLiftSdkModule->ProcessEnding();}); //HealthCheck callback. GameLift invokes this callback about every 60 seconds. By default, //GameLift API automatically responds 'true'. A game can optionally perform checks on //dependencies and such and report status based on this info. If no response is received //within 60 seconds, health status is recorded as 'false'. //In this example, we're always healthy! params->OnHealthCheck.BindLambda([](){return true; }); //Here, the game server tells GameLift what port it is listening on for incoming player //connections. In this example, the port is hardcoded for simplicity. Since active game //that are on the same instance must have unique ports, you may want to assign port values //from a range, such as: //const int32 port = FURL::UrlConfig.DefaultPort; //params->port; 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; //Call ProcessReady to tell GameLift this game server is ready to receive game sessions! gameLiftSdkModule->ProcessReady(*params); #endif
until next time