Compiling Unreal Engine 5 Dedicated Servers for AWS Graviton EC2 Instances

TutoSartup excerpt from this article:
From the top menu, select Build and then select Build Solution… Once the Epic Games Store has been installed, navigate to the Unreal Engine portion of the store by selecting Unreal Engine from the left-hand pane… Navigate to the Samples pane and select Lyra Starter Game: Select Creat…

Epic Games (Epic) is a leading interactive entertainment company and provider of Unreal Engine (UE), one of the most open and advanced real-time 3D creation tools that powers some of the world’s leading games including Fortnite, and is also utilized by creators across industries to deliver cutting-edge experiences.

Epic Games and AWS recently collaborated to introduce AWS Graviton instance support for Unreal Engine. This includes the latest generation, AWS Graviton3 processors, which deliver up to 25 percent higher performance, up to 2x higher floating-point performance, and 50 percent faster memory access based on leading-edge DDR5 memory technology compared with Graviton2 processors. Graviton3 also uses up to 60 percent less energy for the same performance as comparable EC2 instances, which helps you reduce your carbon footprint.

When your game goes viral overnight, success depends on servers that can scale to accommodate player demand. Flexibility is key, and AWS gives you cloud-based compute options to build game servers yourself, integrate existing tools, or even move to a fully managed service with Amazon GameLift. With the launch of Amazon EC2 Graviton3 instances, there are even more options for hosting your dedicated game servers on EC2.

Re-compiling your dedicated game server code to be ARM64 compatible is straightforward with Unreal Engine 5.  This post will show you how to get your first Unreal Engine dedicated game server running on AWS Graviton3 instances.

Pre-Requisites

  • A Windows workstation with a dedicated GPU
  • Visual Studio 2022
  • Visual Studio 2022 Game Development with C++ Module Installed
  • All Visual Studio 2022 .NET Framework 4.6.x Components Installed

Development environment setup

This section will walk you through the steps required to get an Unreal Engine 5 dedicated server compiled for the LinuxArm64 platform which is compatible with running on an AWS Graviton3 instance.

1. Obtain Unreal Engine source code access

In order to compile Unreal Engine dedicated game servers, you’ll need to have Unreal Engine built from source code. In order to get access to UE5 Source Code, please complete the steps outlined here, and then return to this guide.

2. Download Unreal Engine source code

Log in to GitHub, and then navigate to Unreal Engine’s GitHub Repository and download version 5.1.1 or newer. All versions later than 4.27.2 support building dedicated game servers for AWS Graviton. This guide is focused on Unreal Engine 5.

Log in to GitHub, and then navigate to Unreal Engine’s GitHub Repository and download version 5.1.1 or newer. All versions later than 4.27.2 support building dedicated game servers for AWS Graviton. This guide is focused on Unreal Engine 5.

3. Install cross-compile dependencies

In order for Unreal Engine to compile binaries for Linux distributions when running on Windows, you need to install the Cross-Compiling Toolchain. To do this open your web browser and navigate to the Cross-Compiling for Linux page in the Unreal Engine docs. Download and install the v20 toolchain.

In order for Unreal Engine to compile binaries for Linux distributions when running on Windows, you need to install the Cross-Compiling Toolchain. To do this open your web browser and navigate to the Cross-Compiling for Linux page in the Unreal Engine docs. Download and install the v20 toolchain.

4. Compile Unreal Engine from source

You now need to install 7zip to extract the Unreal Engine source code zip archive. I placed the extracted folder in C:UsersAdministratorDocumentsUnrealEngine.

Now, open a Windows Powershell session as an Administrator:

Now, open a Windows Powershell session as an Administrator:

Navigate to C:UsersAdministratorDocumentsUnrealEngine

Navigate to C:UsersAdministratorDocumentsUnrealEngine

Run Setup.bat and wait for it to complete.

Run Setup.bat and wait for it to complete.

Run the GenerateProjectFiles.bat script:

Run the GenerateProjectFiles.bat script:

In C:UsersAdministratorDocumentsUnrealEngine there should now be a file titled UE5.sln. Open it in Visual Studio 2022.

In C:UsersAdministratorDocumentsUnrealEngine there should now be a file titled UE5.sln. Open it in Visual Studio 2022.

If your Visual Studio 2022 install recommends installing any additional components, go ahead and install them now. Once installation has completed, set your solution configuration to Development Editor, and your solution platform to Win64.

If your Visual Studio 2022 install recommends installing any additional components, go ahead and install them now. Once installation has completed, set your solution configuration to Development Editor, and your solution platform to Win64.

From the top menu, select Build and then select Build Solution.

From the top menu, select Build and then select Build Solution.

Building Unreal Engine will take a little while, so grab a cup of your favorite beverage and come back once the build has completed.

5. Open Unreal Engine

Navigate to C:UsersAdministratorDocumentsUnrealEngineEngineBinariesWin64 and launch UnrealEditor.exe

Navigate to C:UsersAdministratorDocumentsUnrealEngineEngineBinariesWin64 and launch UnrealEditor.exe

Lyra Sample Game project setup

Epic provides a multiplayer demo game that includes a client and server with all of the assets and necessary code already created. Using this example project means we won’t have to create all of the assets or code ourself for this demo.

1. Download Lyra Sample Game project from the Epic Games Store

Epic Games includes a free demo game project for Unreal Engine 5 that can be downloaded from the Epic Games Store. The project is called the Lyra Sample Game. In order to download the project, you’ll need to download and install the Epic Games Store. Once the Epic Games Store has been installed, navigate to the Unreal Engine portion of the store by selecting Unreal Engine from the left-hand pane.

Epic Games includes a free demo game project for Unreal Engine 5 that can be downloaded from the Epic Games Store. The project is called the Lyra Sample Game. In order to download the project, you’ll need to download and install the Epic Games Store. Once the Epic Games Store has been installed, navigate to the Unreal Engine portion of the store by selecting Unreal Engine from the left-hand pane.

Navigate to the Samples pane and select Lyra Starter Game:

Navigate to the Samples pane and select Lyra Starter Game:

Select Create Project and select Unreal Engine version 5.1 when prompted.

Select Create Project and select Unreal Engine version 5.1 when prompted.

Select Create Project and select Unreal Engine version 5.1 when prompted.

2. Generate Visual Studio files and adjust project settings

The first step in building and packaging the game is to generate the Visual Studio project files for Lyra. This will allow you to build and edit the Dedicated Server later on. Open the directory where you saved the Lyra Starter Game files from the step above. Secondary select LyrraStarterGame.uproject and select Generate Visual Studio project files:

The first step in building and packaging the game is to generate the Visual Studio project files for Lyra. This will allow you to build and edit the Dedicated Server later on. Open the directory where you saved the Lyra Starter Game files from the step above. Secondary select LyrraStarterGame.uproject and select Generate Visual Studio project files:

Open Lyra in the Unreal Editor by opening the LyraStarterGame.uproject file. There are a couple of things you’ll need to adjust before building the dedicated server and client builds for the Lyra sample. You will need to set the Server Default Map setting to L_Expanse, and to change the number of bots spawned to zero so they don’t immediately start attacking clients as soon as they connect to the server. The bot change will also allow you to more easily view when clients connect/disconnect from the server. You can always add more bots later!

3. Set Server Default Map

In the menu bar select Edit and then select Project Settings.

In the menu bar select Edit and then select Project Settings.

Select Maps & Modes, open the Advanced section under Default Maps and set the Server Default Map to L_Expanse. After you’ve done this you can close the Project Settings window.

Select Maps & Modes, open the Advanced section under Default Maps and set the Server Default Map to L_Expanse. After you’ve done this you can close the Project Settings window.

The next section is changing the number of bots that spawn by default. To do that, select the Content Drawer in the bottom left of the editor screen.

The next section is changing the number of bots that spawn by default. To do that, select the Content Drawer in the bottom left of the editor screen.

Change directories to the Plugins directory, and then search for B_ShooterBotSpawner and select the B_ShooterBotSpawner Blueprint Class that appears.

Change directories to the Plugins directory, and then search for B_ShooterBotSpawner and select the B_ShooterBotSpawner Blueprint Class that appears.

Under the Teams section change Num Bots to Create to zero. After you have made the change select Compile in the upper left section to apply your changes.

Under the Teams section change Num Bots to Create to zero. After you have made the change select Compile in the upper left section to apply your changes.

The project settings have now been configured correctly. Close the Unreal Editor for now. Our next changes will take place over in Visual Studio.

4. Configure and build client and server

In your project’s directory in File Explorer, open the LyraStarterGame.sln file to open the Visual Studio project for our game.

In your project’s directory in File Explorer, open the LyraStarterGame.sln file to open the Visual Studio project for our game.

Verify there is a LyraServer.Target.cs file in your project’s Source directory. If there isn’t one, you’ll need to create one. If there is one, selection Development Server from the Solution Configuration toolbar.

Verify there is a LyraServer.Target.cs file in your project’s Source directory. If there isn’t one, you’ll need to create one. If there is one, selection Development Server from the Solution Configuration toolbar.

From the menu bar, select Build and select Build Solution.

Once that is completed, change the selection in the Solution Configuration toolbar to DevelopmentClient and repeat the build step by selecting Build and selecting Build Solution.

Once that is completed, change the selection in the Solution Configuration toolbar to DevelopmentClient and repeat the build step by selecting Build and selecting Build Solution.

Once that is completed, change the selection in the Solution Configuration toolbar to DevelopmentClient and repeat the build step by selecting Build and selecting Build Solution.

Once that is completed, change the selection in the Solution Configuration toolbar to DevelopmentClient and repeat the build step by selecting Build and selecting Build Solution.

5. Cooking content

Before you can play the game, you will need to cook the content. To do this, reopen the LyraStarterGame project in the Unreal Editor. Select the platforms dropdown, select Windows, and verify the Binary Configuration is set to Development. Now verify the Build Target is set to LyraServer, and then select Cook Content. This will cook the server content so you can launch the server on windows. When the cook process finishes, the server binaries can be found in your project’s Binaries directory. My server binaries path looks like Documents/Unreal Projects/LyraStarterGame/Binaries/Win64/LyraServer.exe.

Before you can play the game, you will need to cook the content. To do this, reopen the LyraStarterGame project in the Unreal Editor. Select the platforms dropdown, select Windows, and verify the Binary Configuration is set to Development. Now verify the Build Target is set to LyraServer, and then select Cook Content. This will cook the server content so you can launch the server on windows. When the cook process finishes, the server binaries can be found in your project’s Binaries directory. My server binaries path looks like Documents/Unreal Projects/LyraStarterGame/Binaries/Win64/LyraServer.exe.

You also need to cook the client content. To do this, change the Build Target to LyraClient and then select Cook Content one more time.

You also need to cook the client content. To do this, change the Build Target to LyraClient and then select Cook Content one more time.

5. Testing the server on Windows

To start the server, open a Powershell window in your project’s source directory and run the following command:

.BinariesWin64LyraServer.exe -log -port 7777

This will start the dedicated server on port 7777. A second terminal will open showing the dedicated server log file:

This will start the dedicated server on port 7777. A second terminal will open showing the dedicated server log file:

Return to the other Powershell window and run the following command to start an instance of the game and connect it to the server. Don’t close the server window or the server process will exit.

.BinaresWin64LyraClient.exe 127.0.0.1:7777 -WINDOWED -ResX=800 -ResY=450

The game should launch and look something like this:

The game should launch and look something like this:

6. Building and packaging dedicated game server for AWS Graviton instances

Now that we have verified that both the game and Dedicated Server are functioning correctly, we can build and package our Dedicated Server for AWS Graviton EC2 Instances. To do this, go back to the Unreal Engine editor. Select the platforms dropdown, select LinuxArm64. Verify that Binary Configuration is set to Development, the Build Target is set to LyraServer, and then select Cook Content.

 Now that we have verified that both the game and Dedicated Server are functioning correctly, we can build and package our Dedicated Server for AWS Graviton EC2 Instances. To do this, go back to the Unreal Engine editor. Select the platforms dropdown, select LinuxArm64. Verify that Binary Configuration is set to Development, the Build Target is set to LyraServer, and then select Cook Content.

Since we will now be running the server on a different host machine and operating system, we will also want to package the content. To do this, open the platforms menu one more time. Select LinuxArm64 and then select Package Content. Select your Binaries directory in the popup file explorer window. This will create a directory in your project’s Binaries folder called LinuxArm64Server.

 Since we will now be running the server on a different host machine and operating system, we will also want to package the content. To do this, open the platforms menu one more time. Select LinuxArm64 and then select Package Content. Select your Binaries directory in the popup file explorer window. This will create a directory in your project’s Binaries folder called LinuxArm64Server.

 Since we will now be running the server on a different host machine and operating system, we will also want to package the content. To do this, open the platforms menu one more time. Select LinuxArm64 and then select Package Content. Select your Binaries directory in the popup file explorer window. This will create a directory in your project’s Binaries folder called LinuxArm64Server.

To copy the server binary over to our AWS Graviton EC2 Instance create a zip archive of the entire folder:

To copy the server binary over to our AWS Graviton EC2 Instance create a zip archive of the entire folder:

Dedicated game server setup

1. Launch AWS Graviton EC2 instance

For the Dedicated Server this example uses a c7g.xlarge EC2 instance running Amazon Linux 2023. You can use any AWS Graviton instance, but a c7g.xlarge instance will suit the purposes of this demo. Head on over to the Amazon EC2 Console and launch your own development instance. When launching Graviton2 instances you’ll need to specify an Arm compatible AMI:

 For the Dedicated Server this example uses a c7g.xlarge EC2 instance running Amazon Linux 2023. You can use any AWS Graviton instance, but a c7g.xlarge instance will suit the purposes of this demo. Head on over to the Amazon EC2 Console and launch your own development instance. When launching Graviton2 instances you’ll need to specify an Arm compatible AMI:

For help creating a Linux EC2 instance, consult the Amazon EC2 User Guide for Linux Instances. When launching this instance, make sure your security group configuration allows your Windows development machine to communicate with the Dedicated Server on UDP port 7777 and TCP port 22. We will use port 7777 for gameplay traffic, and port 22 for SSH.

Once the instance is up and running, copy the zip archive from your Windows workstation to your AWS Graviton c7g.xlarge instance using the tooling of your choice.

2. Run dedicated game server startup script

2. Run dedicated game server startup script

Once the zip archive containing the Dedicated Server binary has been copied to your instance, setup takes a few more steps. First, we’ll want to connect to the instance and unzip the archive. Navigate to the directory you stored the archive in and run “unzip ./LinuxAArch64Server.zip”:

Once the archive has been unzipped you should see a new directory:

Once the archive has been unzipped you should see a new directory:

Navigate to the newly created directory by running cd LinuxArm64Server/ The new directory should look like the following:

Navigate to the newly created directory by running cd LinuxArm64Server/ The new directory should look like the following:

To run the Dedicated Server, we need to add execute permissions to the startup shell script LyraServer-Arm64.sh script. To do this run  chmod +x LyraServer-Arm64.sh

To run the Dedicated Server, we need to add execute permissions to the startup shell script LyraServer-Arm64.sh script. To do this run chmod +x LyraServer-Arm64.sh

To run the Dedicated Server, we need to add execute permissions to the startup shell script LyraServer-Arm64.sh script. To do this run chmod +x LyraServer-Arm64.sh

Now we can start our game server processing by running ./LyraServer-Arm64.sh Once the process has started you should see a screen like the following:

3. Connect to dedicated game server running on AWS Graviton instance

Now that the game server is running and waiting for connections, we can now connect to it from our Windows development machine running the game. We will launch the game as we did before, but with the IP address of the AWS Graviton server.

.BinaresWin64LyraClient.exe 10.2.23.25:7777

If the game doesn’t immediately connect, the Dedicated Server process may have gone to sleep. Simply re-start the server process and reconnect. Once the game connects, you should see something like this:

If the game doesn’t immediately connect, the Dedicated Server process may have gone to sleep. Simply re-start the server process and reconnect. Once the game connects, you should see something like this:

Conclusion

Now that you’ve gotten the example game up and running it’s time to cleanup the resources you created. Make sure to terminate any resources that you created following along with this tutorial so you don’t get charged for resources you’re no longer using.

You have now successfully built and compiled the Project Lyra example game for both Windows and AWS Graviton EC2 instances. You can now take advantage of up to 40% better price performance over comparable current generation x86-based instances by hosting your dedicated servers on AWS Graviton instances. Now that you know how to compile an AWS Graviton compatible game server, test your game servers on AWS Graviton instances!

Compiling Unreal Engine 5 Dedicated Servers for AWS Graviton EC2 Instances
Author: Tyler Jones