AWS for Games Blog
Compiling Unreal Engine 4 Dedicated Servers for AWS Graviton EC2 Instances
Epic Games is a leading interactive entertainment company responsible for some of the world’s largest games including Fortnite, and also develops Unreal Engine, Unreal Engine is a world leading open and advanced real-time 3D creation tool. Continuously evolving, it not only powers the world’s leading games, it also offers creators across industries the freedom and control to deliver cutting-edge content, interactive experiences, and immersive virtual worlds.
To help developers of all shapes and sizes build, run, and grow amazing games, Epic Games and AWS have collaborated to bolster AWS Graviton2 instance support for Unreal Engine. AWS Graviton processors are custom built by AWS using 64-bit Arm Neoverse cores to deliver the best price performance for your cloud workloads running in Amazon EC2. With AWS Graviton2 support, Unreal Engine creators can utilize up to 40% improved price performance over comparable current generation x86-based instances.
Full support for AWS Graviton2 will be released in Unreal Engine 4.27, with further improvements in future releases. Unreal Engine 4.27 previews are available via the Epic Games launcher and GitHub. ARM64 Support is also merging into earlier versions of Unreal Engine in order to benefit developers running games and applications on AWS.
If your game becomes a smash hit overnight, continued success depends on reliable servers capable of scaling to player demands. Flexibility is essential, and AWS offers the broadest and deepest cloud-based compute platform, whether you would like to build game servers yourself, integrate with existing tools, or even move to a fully managed service.
The introduction of AWS EC2 Graviton2 instances provides even more options for hosting your dedicated game servers on Amazon EC2, delivering a major leap in performance and capabilities over first-generation AWS Graviton processors. Re-compiling your dedicated game server code for compatibility with ARM64 is simple and easy with Unreal Engine 4 (UE4). Learn how to create a dedicated game server with Unreal Engine and AWS Graviton2 instances by following the step-by-step guide below:
Prerequisites
- A Windows 10 workstation with a dedicated GPU
- Visual Studio
Development environment setup
This section guides you through getting an Unreal Engine 4 dedicated server compiled for the Arm platform and compatible to run on an AWS Graviton2 instance. Most of the following instructions are independent of x86 and Arm platforms. This guide focuses on building a clean and working environment on Windows prior to building the game for AWS Graviton2 instances.
Obtain Unreal Engine source code access
To compile Unreal Engine dedicated game servers, you must have Unreal Engine built from source. To get access to UE4 Source Code, please complete the steps outlined here, and then return to this guide.
Install Visual Studio Community Edition
To build Unreal Engine from source, I recommend downloading Visual Studio 2019 Community Edition. You can download Visual Studio 2019 Community Edition for free here. Once the download is complete, proceed to the install.
To build the Unreal Engine editor and Unreal Engine projects, you must install some optional features. Navigate under the Workloads Tab, select “Game development with C++”, then select the following options on the right-hand side:
- C++ profiling tools
- C++ AddressSanitizer
- Windows10 SDK (10.0.18362.0)
- Unreal Engine Installer
Select the Individual components tab, and then scroll down to “Compilers, build tools, and runtimes” and select MSBuild.
You are now ready to install Visual Studio 2019. Click Install, and allow time to complete.
Download Unreal Engine source code
Log in to GitHub, and navigate to Unreal Engine’s GitHub Repository and download version 4.26.2 or newer. While official support is releasing as part of 4.27, the changes have already been merged in 4.26.2 and later versions. I am using 4.26.2 for this guide.
Install cross-compile dependencies
For Unreal Engine to compile binaries for Linux distributions when running on Windows, you need to install the Cross-Compiling Toolchain. To do this, navigate to the Cross-Compiling for Linux Unreal Engine documentation page. Download and install the v17 toolchain.
Compile Unreal Engine from source
Extract the Unreal Engine source code zip archive. I placed the extracted folder in “C:\Users\Administrator\Documents\UnrealEngine”.
Open a Windows PowerShell session as an Administrator:
Navigate to C:\Users\Administrator\Documents\UnrealEngine\
Run Setup.bat
and wait for it to complete.
Run the GenerateProjectFiles.bat
script
In C:\Users\Administrator\Documents\UnrealEngine there should now be a file called UE4.sln. Open it in Visual Studio 2019.
If your Visual Studio 2019 install recommends installing any additional components, install them now. Once installation is complete, set your solution configuration to “Development Editor”, and your solution platform to “Win64”.
In the Solution Explorer on the right hand column, right click the UE4 build target and select “Build”.
Unreal Engine will take a little time, so grab a cup of your favorite beverage and return once the build has completed.
Open Unreal Engine
Navigate to C:\Users\Administrator\Documents\UnrealEngine\Engine\Binaries\Win64 and launch UE4Editor.exe
Third person example game project setup
In the Unreal Project Browser, create a new games project.
Under Select Template, select “Third Person”, and click Next.
Under Project Settings make sure “C++ Project” is selected, name your project GravitonServer and select Create Project.
The project should now automatically open in Visual Studio. However, to build a dedicated server, you must make a few file changes and then regenerate the Visual Studio project file. Close the Visual Studio window and make the following changes.
Create dedicated server build target
To build a dedicated server for your game, you must create a dedicated server build target. To do this, you will copy the editor target file and turn it into a dedicated server target file.
Open Windows Explorer and navigate to C:\Users\Administrator\Documents\Unreal Projects\GravitonServer\Source.
Copy the GravitonServerEditor.Target.cs file and name the new one GravitonServerServer.Target.cs
Open GravitonServerServer.Target.cs in Visual Studio
Replace both instances of GravitonServerEditorTarget
with GravitonServerServerTarget
. Change Type = TargetType.Editor
to Type = TargetType.Server.
Your final file should look like the following image:
Now, regenerate the Unreal Engine project files so Unreal Engine recognizes the new server build target. To do this, navigate to “C:\Users\Administrator\Documents\Unreal Projects\GravitonServer”, right click GravitonServer.uproject, and then click “Generate Visual Studio project files.”
Once the files have been generated, double-click “GravitonServer.sln” to open the Visual Studio project. Once the project has loaded, you need to make changes to the editor settings to setup a dedicated server build.
In the “Solution Configuration” dropdown box, switch to “Development Server.”
Now you can build the dedicated server project. Simply right click the GravitonServer project name on the right, and select “Build”.
Before you can make tweaks to your game and package our project, recompile your editor build target. To do this, simply change the “Solution Configuration” drop-down to “Development Editor.”
Now build your development editor target by right clicking the project name and clicking “Build” one more time.
Then, open your project in the Unreal Engine editor and package this game for delivery. To do so, double-click the “GravitonServer.uproject” file in Windows Explorer:
Since you’re using the default 3rd Person Example Project, the GravitonServer project should look like the below image once it has successfully loaded:
Add startup map
Add a new map to your project. This will be what the user sees when they load the game. To keep this tutorial simple, the new map will just be a black screen. Start by double-clicking the “Maps” folder:
Right click and select “New Level”, and then name the new file “EntryLevel”.
Now open your new level. Double-click “EntryLevel” and select “Save Selected” when prompted.
Configure map settings
Now, configure which map the client and dedicated server will load by default. For this tutorial, the client will load EntryLevel by default, and the dedicated server will load ThirdPersonExampleMap by default. To do so, open Project Settings by going to Edit → Project Settings.
Then select “Maps & Modes” and expand the Advanced Settings menu and change “Global Default Server Game Mode” to “GravitonServerGameMode”.
Now change the default maps that are loaded by the dedicated server and game client. Expand the default maps section. Change the “Game Default Map” to “EntryLevel”, and “Server Default Map” to “ThirdPersonExampleMap”:
Next, change the packaging settings to package maps with the game when it is built and packaged for deployment. To do this, click the “Packaging” option on the left menu and expand it by clicking the dropdown arrow.
Now add your maps to the build package. Scroll down to “List of maps to include in a packaged build”, click the “+” button and Two new rows will pop up beneath.
Click the three dots next to the box to add your maps and a file explorer window should open. Navigate to “C:\Users\Administrator\Documents\Unreal Projects\GravitonServer\Content\ThirdPersonCPP\Maps” and select the “ThirdPersonExampleMap.umap” file. Repeat this for the “EntryLevel.umap” file. When completed, your project settings screen should look like the following image:
For this tutorial, use the in-game console function to connect to the dedicated server for the game.
Note: In a production game this would usually be handled by custom matchmaking logic, but that exceeds the scope of this tutorial.
To use the in-game console to connect to the dedicated server, under Packaging settings, scroll down to the “Project” section and verify that “Build Configuration” is set to “Development”.
You can build and package your game! Build the game client first, and then the dedicated server binaries. To verify the server works correctly, first build and package the game for Windows and run it on localhost to ensure the client can connect properly. Once you know the game is working, you will then build and package it for AWS Graviton instances.
Building and packaging the Game and dedicated game server
The first step in building and packaging the game is ensuring the right build target is selected. Build the game first. To verify that the correct build target is selected, go to File → Package Project → Build Target and verify that “GravitonServer” is selected.
To build the game, select File → Package Project → Windows (64-bit). A Windows Explorer window will open, in which you can select where the binaries will be saved once they’re built and packaged.
I have selected “C:\Users\Administrator\Documents\Unreal Projects\GravitonServer\Binaries”. Place them wherever you want to store them. Once you’ve decided on where, click “Select Folder” and the build process will begin.
In the Unreal Editor, selecting “Show output log” will let you monitor the build process. This may take some time, so now is a good time to get another cup of your favourite beverage. Once the game binary has been built and packaged, you can build and package the dedicated server binary. To do this, change the build target to “GravitonServerServer” by going to File → Package Project → Build Target, and selecting “GravitonServerServer”.
Select File → Package Project → Windows (64-bit) one more time. Select the place to save your built and packaged dedicated server binaries, and then wait for the build to complete. Once the build has completed, you will now start the dedicated server and connect the client to it.
Running dedicated game servers on Windows
To start the dedicated server process in order to verify that everything is running properly, start the dedicated server process with logging enabled. Open Powershell, and change directories to wherever you stored your dedicated server binaries. I used “C:\Users\Administrator\Documents\Unreal Projects\GravitonServer\Binaries\WindowsServer”
To start the server, type .\GravitonServerServer.exe -log
which should start the dedicated server with logging enabled. A new window should now open containing the server logs. This will display the port that the server is listening on. In my case, it’s port 7777, as shown in the server logs here:
Connect to dedicated game server running on Localhost
Now let’s verify that your game can connect to your dedicated server running on Localhost. To launch the game, open Windows Explorer and navigate to “C:\Users\Administrator\Documents\Unreal Projects\GravitonServer\Binaries\WindowsNoEditor”, and then double-click “GravitonServer.exe” to get started.
The game should open to a black screen in the Unreal Editor, which is the EntryLevel map that you created earlier. Once the game has opened, open the in-game console by pressing the ` key on your keyboard. To connect to the server, type “Open “127.0.0.1:7777”” and push enter:
If the game doesn’t immediately connect, then the dedicated server process may have gone to sleep. Simply stop and restart the server process running in PowerShell and try connecting again. Once the game connects, you should see the in-game experience in the Unreal Editor.
Building and packaging dedicated game server for AWS Graviton2 Instances
Now that you have verified that both the game and dedicated server are functioning correctly, you can now build and package your dedicated server for EC2 Instances powered by AWS Graviton2. Go back to the Unreal Engine editor. Select File → Package Project → Linux → Linux (AArch64):
A Windows Explorer window will open, allowing you to select where the binaries will be saved once they’re built and packaged. I have selected “C:\Users\Administrator\Documents\Unreal Projects\GravitonServer\Binaries”. Place them wherever you want to store them. Click “Select Folder” and the build process will begin. Once the build has completed, you should see a folder titled “LinuxAArch64Server” wherever you chose to save your binaries.
To more easily copy over to your AWS Graviton2 powered EC2 Instance, create a zip archive of the entire folder which you will copy to your AWS Graviton2 EC2 Instance.
Dedicated game server setup
Launch AWS Graviton2 EC2 Instance
For the dedicated server, I will use an m6g.large EC2 instance running Amazon Linux 2. Feel free to use any m6g instance size, but an m6g.large instance should be large enough. Head over to the AWS console and launch your own development instance. When launching Graviton2 instances, you’ll need to specify an Arm compatible AMI.
When launching this instance, ensure that 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 running, copy the binary from Windows to the AWS Graviton2 instance using your preferred tooling.
Run dedicated game server startup script
Once the zip archive containing the dedicated server binary has been copied to your instance, the setup takes a few more steps. First, 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. Navigate to the newly created directory by running cd LinuxAArch64Server/
The new directory should look like the following image:
To run the dedicated server, add execute permissions to the startup shell script GravitonServerServer-AArch64.sh
script. To do this, execute chmod +x GravitonServerServer-AArch64.sh
Now you can start your game server processing by running ./GravitonServerServer-AArch64.sh
Once the process has started, you should see the following image:
Connect to dedicated game server running on AWS Graviton2 Instance
Now that the game server is running and waiting for connections, connect to it from the Windows development machine running the game. Launch the game as before. It should open to a black screen, which is the EntryLevel map you created earlier. Once the game has opened, open the in-game console by pressing the ` key on your keyboard. Once the in-game console is open, connect to the public IP address of your instance. Once the game connects, you should see something like this:
You have now successfully built and compiled an Unreal Engine example game for both Windows and AWS Graviton2 EC2 instances. You can now take advantage of up to 40% improved price performance over comparable current generation x86-based instances by hosting dedicated servers on AWS Graviton2 instances. Now that you can compile an AWS Graviton2 compatible game server, go ahead and test your game servers on Graviton2 instances.