Setting Up Dedicated Servers

How to set up and package a dedicated server for your project.

Choose your operating system:

Windows

macOS

Linux

The server-client model used by Unreal Engine represents network multiplayer games with one server acting as the host of the game, and players joining that game as clients . The true game state is moderated by the server, while each player controls their pawns remotely with an autonomous proxy . The server then replicates changes out to each connected client so that all players experience a very close approximation of the game being played on the server.

Where a listen server represents a player hosting a game on their machine, a dedicated server is a server that runs headlessly. A headless server does not render any visuals, and there is nobody playing on it locally. This enables a dedicated server to focus on gameplay logic and moderating incoming information from clients, making the most of its resources for hosting a game. Additionally, this ensures a level playing field between all players participating in a multiplayer game. While a listen server is often acceptable for casual multiplayer and cooperative play, dedicated servers are ideal for large-scale or competitive games.

This how-to will show you how to build and package a dedicated server for your own multiplayer games.

1. Required Setup

To follow the steps in this how-to, your project needs to satisfy the following requirements:

  • You must be using a source build of Unreal Engine, which you can download from the Epic Games Github .

    • If your project is using a binary build from the Epic Games Launcher, you will need to migrate it to a Github source build.

  • You must have a C++ project that can support server-client multiplayer gameplay.

    • If you are using a Blueprint project, you will need to convert it to a C++ project before you can proceed.

This example will use a new project from the third-person template as an example.

To build a new multiplayer project from scratch, refer to the [Network Multiplayer Quick Start Guide](InteractiveExperiences/Networking/Quickstart], which adds some basic multiplayer mechanics to the third-person template.

2. Setting Up a Server Build Target

Dedicated servers are a separate build target for your project. When you create one, you create a different executable compared with the base game. Instead of being called "TestProjectGame.exe," it would be "TestProjectServer.exe," and launching that executable would start a dedicated server on your computer. This section will walk you through the process of adding the server build target to your project and compiling it.

  1. Open the C++ solution for your project. This will be located in your project folder. Here it is called MyProject.sln .

    ProjectSolutionInFolder.png

    If you do not have a C++ solution, you can right-click your .uproject file and click Generate Visual Studio Project Files to create one.

  2. In the Solution Explorer , unfold the Source folder and locate the [Project].Target.cs file. This is the default build target for your project. There is also a [Project]Editor.Target.cs file for configuring how the Unreal Editor builds for this project. We will create the server build target in this same directory.

    TestProjectTarget.png

  3. Open the Source folder in Windows Explorer . Create a copy of [ProjectName].Target.cs and rename it [ProjectName]Server.Target.cs . Here, the resulting file is called TestProjectServer.Target.cs .

    ServerTargetInFolder.png

  4. Return to Visual Studio, then click and drag *Server.Target.cs from your Explorer window into the Source folder in the Solution Explorer .

    TestProjectServerTarget.png

  5. Open [ProjectName]Server.Target.cs and replace its contents with the following target file instructions:

    // Copyright Epic Games, Inc. All Rights Reserved.
    
    using UnrealBuildTool;
    using System.Collections.Generic;
    
    public class TestProjectServerTarget : TargetRules //Change this line according to the name of your project
    {
        public TestProjectServerTarget(TargetInfo Target) : base(Target) //Change this line according to the name of your project
        {
            Type = TargetType.Server;
            DefaultBuildSettings = BuildSettingsVersion.V2;
            ExtraModuleNames.Add("TestProject"); //Change this line according to the name of your project
        }
    }

    Be sure to replace all instances of TestProject with the name of your own project.

  6. Locate the .uproject file for your project in its base directory, then right-click it and select Generate Visual Studio Project Files . This will regenerate the Visual Studio solution for your game, and it will discover your *Server.Target.cs file .

  7. Select the Development Editor build configuration.

  8. Build your solution by clicking Build > Build Solution in the toolbar. You can also do this through the context menu in the Solution Explorer window.

  9. Select the Development Server build configuration and build the solution again.

  10. Locate your project's Binaries/Win64 folder. You should see Server files inside this folder, including [ProjectName]Server.exe .

    DedicatedServerExecutables.png

    This executable is the one you will use to deploy a dedicated server.

3. Setting Up Entry and Default Maps

To test our dedicated server, we need to set up our default maps for our project so that the server will run a playable map, and so that users will connect to the server. There are many ways to accomplish this, but the quickest and most direct method is to build the connection flow directly into the user's entry map when they start up the application.

  1. Open your project in Unreal Editor . Inside the Content Browser , make sure to relocate all Level files to a Content/Maps folder. This can be done by moving the Maps folder from ThirdPersonCPP into the base Content folder.

    MoveMapFiles.png

  2. Create a new level titled [ProjectName]Entry , where [ProjectName] is replaced with the name of your project. In this example, it will be called TestProjectEntry . You can make this with a blank map as the starting template.

    EntryMap.png

  3. Open the Entry map, then open the Level Blueprint script. From the BeginPlay node, add an Open Level node and give it a value of 127.0.0.1 . This is your local IP address, which means that you are telling the game to connect to a server located on your own computer. If you substitute this value with a valid IP address, you will instead connect to a server located at that address.

    Normally, an entry map is where you would set up your main menu UI. In this example, the entry level simply connects directly to the user's own local IP so that we can quickly connect to the dedicated server. For an example of a fully featured entry map with a UI, refer to the ShooterGame sample project .

  4. Open the ThirdPersonExampleMap and delete the third-person character that is normally pre-placed in the level. Instead, make sure there are two PlayerStarts in the level. This will ensure that when players connect, they have a consistent startup experience.

  5. Open your Project Settings, navigate to Project > Maps and Modes, and unfold the Default Maps. Change them to the following:

    Parameter Name

    Value

    Editor Startup Map

    [ProjectName]Entry

    Game Default Map

    [ProjectName]Entry

    Transition Map

    None

    Server Default Map

    ThirdPersonExampleMap

    This will ensure that the server opens directly to ThirdPersonExampleMap, while users open to the Entry map and connect to the server.

4. Packaging Your Project

  1. Click File > Packaging > Packaging Settings to open your packaging settings.

  2. Unfold the advanced settings at the bottom of the Packaging section by clicking the rectangular button with an arrow.

  3. Locate List of Maps to Include in a Packaged Build and add both your Entry map and ThirdPersonExampleMap .

  4. Click File > Package Project > Windows (64-bit) , and choose a directory to package your project. Here we use TestProject/Packaged as our output folder.

  5. Click File > Package Project > Build Target . You should see [ProjectName] Server alongside the normal build target. Select this option.

  6. Package the project again, and choose the same output folder as before. There should now be a folder called WindowsServer alongside WindowsNoEditor .

5. Launching and Testing Your Dedicated Server

Finally, it's time to test our dedicated server.

  1. Open the WindowsServer folder you created in the previous section, then locate [ProjectName]Server.exe . Here it's called TestProjectServer.exe.

  2. Create a shortcut to the Server.exe , edit its name, and add " - ThirdPersonExampleMap" to the end of it. Here we have renamed it TestProjextServer.exe - ThirdPersonExampleMap .

  3. Right-click the server shortcut and open its properties . Add "-log" to the end of its Target field and click Apply .

    ShortcutProperties.png

    This will make it so that when we run the dedicated server, it will display a log in a command prompt. Per our setup in the previous sections, the server will already open to ThirdPersonExampleMap, so there isn't any need to add map parameters to this shortcut.

  4. Double-click the shortcut to launch your dedicated server. A command prompt window will open displaying an output log. If launching the server is successful, you will see an output on how many seconds it took to bring up the level at the bottom.

    DedicatedServerCommandPrompt.png

  5. Go to the WindowsNoEditor folder and double-click TestProject.exe . It will launch the game in a new window and appear to go directly to ThirdPersonExampleMap.

  6. Use ALT+Tab to leave the game window, then run TestProject.exe to launch a second instance of the game. If it is successful, you will see the player from the window you launched. You can also check the server log to see confirmation of both players connecting to the server.

DedicatedServerRunning.png

Congratulations! You have successfully built, packaged, and tested a dedicated server for your project.

On Your Own

This example teaches you the basics of how to build, package, and test a server on your local machine. The next step from here would be providing a functioning frontend, expanding on your game's gameplay, and providing a means for players to connect to your dedicated server over the internet.

To see an example of a working frontend, you can refer to the ShooterGame example project , which uses one in the ShooterEntry map.

To begin expanding on your gameplay, you can refer to the Network Multiplayer Quick Start Guide.

To connect to a server over a network, you can provide that server's IP address in place of 127.0.0.1. You can incorporate this into a simple UMG UI instead of running off BeginPlay in the Entry map. You can also use the "open" command in the console and provide the IP address in place of a level name.

Help shape the future of Unreal Engine documentation! Tell us how we're doing so we can serve you better.
Take our survey
Dismiss