Building the infrastructure
The infrastructure code for this project is relatively simple. First, we will create a new AMI with Packer containing our dedicated server, our Dockerfile, and the Docker service. Then we will create the Terraform code that will create a new instance of the AMI.
I will also create a security group that will allow UDP 7777 into the instance. Obviously this is far from a production setup, but I think is a good way to demonstrate automating the creation and deployment process of our dedicated server as simply as possible.
For these steps, I will assume you have basic AWS knowledge including how to setup AWS credentials to access the AWS API.
We will first start with the Packer code that will create the AMI containing Docker, our dedicated server, and the Dockerfile. The first step in creating our AMI is to tar our Linux dedicated server so that we can upload it with Packer. To do this, open up MinGW (Terminal that comes with Git for Windows) and cd into the SheepsGateGame/Binaries directory where we exported the Linux server. Run the following tar command to tar and gzip the server binary:
tar -czf unreal-dedicated.tar.gz ./Linux
After the archive has been generated, copy or move it to the building-ue4-dedicated-server-blog-1/server directory. See the folder structure below.
Now it is time to build the AMI. To do this, run the following command. I have provided a variables.json file where you can include your AWS API access and secret keys.
packer.exe build -var-file=packer/variables.json packer/docker_instance.json
The Packer file will create an AMI that will install Docker, upload the Dockerfile and the Unreal Engine dedicated server archive.
After the AMI creation is completed, it is time to run the Terraform code to create an instance from the API and a security group that will allow the game client to connect to the server. I have also provided a var.tfvars file that you can use to set your AWS API access and secret keys.
terraform plan -var-file=vars.tfvars -out plan
terraform apply plan
After Terraform has executed, you will get the public IP address of the instance as output. This is the IP we will use to connect our client to the server.
Copy this IP and open up Unreal Engine editor. We will now configure the EntryLevel blueprint to connect to this IP when the BeginPlay event occurs. Open the Blueprint editor and change the level IP from 0.0.0.0 to the instance’s public IP.
Compile the blueprint and exit out of the editor. Now play the game. You should see the SheepsGate level render and the player character spawn into the scene. Because we are using a server authoritative client-server model, the client will render whatever level gets sent by the server. This is why we set the default server map to our SheepsGate level and the default client map to the empty EntryLevel.
Congratulations, you have successfully connected your game client to a dedicated server running in AWS. Now it is time to package the client.
You have successfully created an Unreal Engine dedicated server and built the required infrastructure to host it on AWS. As stated earlier, this is far from a production setup, but I hope that this tutorial has given you a good idea of how the client-server model in Unreal Engine works and how dedicated servers can be hosted in the cloud.
You can destroy the infrastructure in AWS with the following command.
terraform destroy -var-file=vars.tfvars
Thanks for reading!
Creating a project
After the editor build has completed, we can now start a new instance of the editor and create a demo project. To do this, press F5 to start a new instance of the Unreal Engine. For the purpose of this demo we will create a simple game called SheepsGate (taking inspiration from Dauntless here). This game will utilize the Third Person template provided by Epic.
Select Games -> Next -> Third Person template -> Next. Select the Blueprint drop down under settings and choose C . Change the project name to SheepsGateGame. Select Create Project. Congratulations, we now have a Third Person sample project.
Packaging the client
For the final step of this tutorial we will package the client. This is a relatively straight forward process, so I will try and keep this section as brief as possible.
To package the client, we first need to switch the build target from server to client. To do this select File -> Package Project -> Build Target -> SheepGateGame.
We will be packaging the client for Windows, so select File -> Package Project -> Windows -> Windows 64. Save the client package under the Binaries/Win64 folder within the SheepsGateGame source directory.
Just like the server, the client packaging process will take a few minutes. When the build has completed, you will see the following Build Successful output in the log.
After the packaging has completed, open up the project source directory and navigate to the Binaries/Win64 folder. You should see the following folder structure.
Double click on SheepsGateGame.exe to start the client process. The client will connect to the server in AWS and the SheepsGate level will render in the client.
Packaging the server
Because the goal of this project is to run our dedicated server in a Linux Docker container, we will need to package our server for Linux. To do this, you will need to install the Linux cross compile dependencies I linked to at the beginning of this post.
Now we are ready to begin packaging the server. To package the server for Linux click File -> Package Project ->Linux -> Linux.
You will need to choose an output directory. I like to create a Linux directory in the project Binaries folder.
After selecting the output folder, the packaging will begin. Packaging may take a few minutes, but after it has completed it is time to start writing the infrastructure code. For these steps you will need a text editor (I will be using Visual Studio Code), Packer, Terraform, and an AWS account.
Unreal tournament 1999 server hosting
The locations we support are
Los Angeles, Dallas, New York, London, Paris, Madrid, Stockholm, Moscow, Frankfurt, Singapore, Sydney.