Twitter LogoFacebook Logo
Multiplayer with GameLift - Local Dedicated Game Server
Learn how to create a server build and host it locally with multiplayer demo.
By: King

Hello, in this tutorial, I’ll show you how to create a server build of your project and host it on your computer so you will know what to expect when we push it to GameLift.

To give an general idea of how multiplayer work with GameLift is that there's a dedicated server hosting a specific version of our game.

The players can then run that version of the game, connect to the server, and host virtual rooms that people can join and see each other. 

You'll see how we can do this on your computer.

Creating the Server.Target Build File

Step 1:

Launch the Github desktop app and make sure you have UnrealEngine selected and commit the changes.

Image from Codeible.com

Step 2:


Click on Show In Explorer to open the project in the file explorer window. Then navigate to Engine > Binaries and locate the executable file for the Unreal Engine editor for your system and launch it.

For Windows, it is in Win64, and the executable is called UnrealEditor.

Step 3:


Once the Editor is open, create a Third Person C++ project.

It should open Visual Studio. The next step is to create the Server Target Build file for the project.

Step 4:

Close Visual Studio and navigate to the directory of the project that was created.

Navigate to the Source directory and make a copy of the Editor.Target file.

Step 5:


Rename the file by changing Editor to Server and remove everything after Target.

MyGameNameServer.Target

Step 6:

Open the file in a text editor. Replace Editor with Server in the class name. Then do the same to the constructor.

For TargetType.Editor, change it to TargetType.Server.

using UnrealBuildTool;
using System.Collections.Generic;

public class MyGameNameServerTarget : TargetRules
{
   public MyGameNameServerTarget (TargetInfo Target) : base(Target)
   {
      Type = TargetType.Server;
      DefaultBuildSettings = BuildSettingsVersion.V2;
      IncludeOrderVersion = EngineIncludeOrderVersion.Unreal5_1;
      ExtraModuleNames.Add("MyGameName");
   }
}

Save the changes and close it. 

Step 7:


Go back to the root directory. Right click on the Unreal Engine project file and generate Visual Studio project files.

Step 8:


Now open the Visual Studio project file with Visual Studio.

Make sure you have Developer Editor selected and launch the app.

Keep in mind that this may take a long time if you are launching it for the first time.

Creating the Server and Client Map

Step 1:


Once you are In the Editor, make two copies of the Third-person Map

Step 2:


Rename one to ClientMap and the other to ServerMap.

Step 3:


Open the server map. 

Move the Third Person Template text to the center of the map. 

Then change the text to Server Map  so we know that we are in the server.

Configuring the Project Settings

Step 1:


Once you have the two maps, we need to configure some project settings. Click on Edit then Project Settings.

Step 2:


Under Projects, click on Maps and Modes.

For the Editor Startup Map, select the ClientMap. For the Game Default Map, also select ClientMap.

Step 3:


Expand the Advanced settings menu. For Server Default Map, select the ServerMap.

Step 4:


Now click on Packaging under Project

Expand the Advanced settings menu and look for "List of maps to include in a packaged build." 

Add 2 elements then add the Client and Server maps by browsing the project files.

Creating the Server Build

Now we can proceed to create the server build. Close the Project Settings window. 

Step 1:

Click on the Platforms button in the editor. 

Select the platform you are using and make sure the target is the Server one. 

If you do not see this, it means you did not create the Server Target build file correctly or you did not generate the Visual Studio project files after you created it.

Step 2:

Click Package Project and create a folder to store the packaged files.

This will also take some time to complete if it is the first time.

Step 3:

Once the build finishes, navigate to the directory of your packaged files. 

You should see the Server executable. 

Step 4:


Right click on it and create a Shortcut. 

Step 5:


Right click on the Shortcut and select properties. 

At the end of the Target, add:

-log

This will allow us to see the server logs on the terminal while it is running. Without this, the server will start but it’ll be hard to know if it is running.

Step 6:


Click Apply and OK.

Step 7:

Launch the server and you should see a terminal window. This mean that the server is running.

Testing Multiplayer with the Local Server

Step 1:

To test this, go back to the Editor. 

Click on the button with the 3 vertical dots. In Number of Players, put 2 and make sure the Net Mode is Play Standalone.

Step 2:


Open the ClientMap and launch the app.

You should see 2 games running.

Step 3:


To connect to the server, select one of the game and press the Tilde key on the keyboard. 

It is the key on the left side of the 1 key and under the Escape key.

You should see the command prompt at the bottom. 

Step 4:

Type open followed by 127.0.0.1:7777 in the command prompt.

127.0.0.1 means localhost and 7777 means the port.

If we take a look at the server logs, the default port it is listening on is 7777

Step 8:


Now if we hit enter and execute the command, we should be transported to the server map.

Step 9:


Do the same on the other client. 

As you can see, both players joined on the same map. 


This is what we’ll do with GameLift. We’ll use it to host the server build and people will be able to create and join instances of the game.

That’s all for this tutorial. If you find this helpful, give it a like, share, and subscribe to support the channel.


Sign In