Dedicated Server Guide (Windows)

NOTE - This is supposed to be an updated version of the Legacy equivalent, and the plan is to split it into three pages: Dedicated Server Guide (Windows) Dedicated Server Guide (Linux) Building Unr...

Updated over 4 years ago

NOTE - This is supposed to be an updated version of the Legacy equivalent, and the plan is to split it into three pages:

Prerequisites

In order to build dedicated servers for Windows, you need a source build version of Unreal Engine, to see how to setup this, check out: Building Unreal Engine from Source

Dedicated Server from a brand new project

Open up source unreal engine, select c++ and third person template, give it a suitable name and save location

File:Createproject.png

once the project and visual studio have finished completely loading, close them both down.

Note again wait until the header files have all been parsed in visual studio before closing. it may prompt you to save just click ok.

Dedicated Server from a blueprint only project

if your project was made with a none source or different engine version or was simply only BLUEPRINTS to begin with you will not be able to make a dedicated server until you add some c++ code.

So simply go to add new, c++ class, an empty class will suffice, and you can delete it later.

Once you have a source directory, right click on the .uproject file and generate visual studio project files. This should create an .sln in the project directory that you can open in visual studio.

Preparing the project for building

Target file instructions for engine version 4.14

open up the previously created project folder from the file explorer inside there will be a folder called source . open this up

File:Sourcefolder.png

inside you will find some visual studio source files. take one of the source files and copy and paste it and then rename it to match the others . format is gamenameServer.Target.cs so in my case because my project game name is called test i would rename my file to testServer.Target.cs like so

File:Testserver.png

right click this newly created file and click edit

File:Editfile.png

this will normally bring up a notepad so you can edit the file , although you can use any kind of text or code editor you wish. notepad is just quick and easy.

delete anything that is in the file so it is completely blank and replace with this code/text

// Copyright 1998-2016 Epic Games, Inc. All Rights Reserved.

using UnrealBuildTool;
using System.Collections.Generic;

public class ShooterGameServerTarget : TargetRules
{
      public ShooterGameServerTarget(TargetInfo Target)
      {
         Type = TargetType.Server;
         bUsesSteam = true;
      }

       //
       // TargetRules interface.
       //

       public override bool GetSupportedPlatforms(ref List`` OutPlatforms)
       {
            // It is valid for only server platforms
            return UnrealBuildTool.UnrealBuildTool.GetAllServerPlatforms(ref OutPlatforms, false);
       }

       public override void SetupBinaries
       (
          TargetInfo Target, ref List`` OutBuildBinaryConfigurations,
          ref List`` OutExtraModuleNames
       )
       {
         OutExtraModuleNames.Add("ShooterGame");
       }
}

next you have to make 3 changes to the file

first find this line of code at the top

public class ShooterGameServerTarget : TargetRules

and change it so that it has your game name instead so in my case my game is called test so i would change the line of code to this

public class testServerTarget : TargetRules

next underneath it find this line of code and do the same as before and change the name to match your game

public ShooterGameServerTarget(TargetInfo Target)

so again in my case my game name is test so i would change this line of code to this

public testServerTarget(TargetInfo Target)

and finally find this line of code and do the same as before and change the name to match your game

OutExtraModuleNames.Add("ShooterGame");

so again in my case my game is called test so i would change this line of code to this

OutExtraModuleNames.Add("test");

Now just save the file with the same name and close it.

Target file instructions for engine version 4.15

// Copyright 1998-2017 Epic Games, Inc. All Rights Reserved.

using UnrealBuildTool;
using System.Collections.Generic;

[SupportedPlatforms(UnrealPlatformClass.Server)]
public class ShooterGameServerTarget : TargetRules      // Change this line of code as shown in the previous steps
{
 
    public ShooterGameServerTarget(TargetInfo Target)  // Change this line of code as shown in the previous steps

       {

     Type = TargetType.Server;

      bUsesSteam = false;

       }

        //
        // TargetRules interface.
        //
            public override void SetupBinaries
            (
             TargetInfo Target,
             ref List`` OutBuildBinaryConfigurations,
             ref List`` OutExtraModuleNames
             )
               {
                OutExtraModuleNames.Add("ShooterGame");     // Change this line of code as shown in the previous steps
               }
  }

Target file instructions for engine version 4.16

// Copyright 1998-2017 Epic Games, Inc. All Rights Reserved.

using UnrealBuildTool;
using System.Collections.Generic;

[SupportedPlatforms(UnrealPlatformClass.Server)]
public class ShooterGameServerTarget : TargetRules    // Change this line of code as shown previously
{
   public ShooterGameServerTarget(TargetInfo Target) : base(Target) // Change this line of code as shown previously
       {
              Type = TargetType.Server;
              ExtraModuleNames.Add("ShooterGame");   // Change this line of code as shown previously
       }
}

Target file instructions for engine version 4.17

// Copyright 1998-2017 Epic Games, Inc. All Rights Reserved.

using UnrealBuildTool;
using System.Collections.Generic;

[SupportedPlatforms(UnrealPlatformClass.Server)]
public class ShooterGameServerTarget : TargetRules   // Change this line as shown previously
{
       public ShooterGameServerTarget(TargetInfo Target) : base(Target)  // Change this line as shown previously
       {
        Type = TargetType.Server;
        ExtraModuleNames.Add("ShooterGame");    // Change this line as shown previously
       }
}

Target file instructions for engine version 4.18

// Copyright 1998-2017 Epic Games, Inc. All Rights Reserved.

using UnrealBuildTool;
using System.Collections.Generic;

[SupportedPlatforms(UnrealPlatformClass.Server)]
public class ShooterGameServerTarget : TargetRules   // Change this line as shown previously
{
       public ShooterGameServerTarget(TargetInfo Target) : base(Target)  // Change this line as shown previously
       {
        Type = TargetType.Server;
        ExtraModuleNames.Add("ShooterGame");    // Change this line as shown previously
       }
}

Switch Unreal engine versions & generate project files

next inside the project folder right click the uproject file and when the menu pops up select "switch unreal engine versions"

if when you right click on a uproject file you dont get a menu that looks like this

File:Build server.png

then follow this step below from the read me file.

One last thing. YouÔÇÖll want to setup your Windows shell so that you can interact with .uproject files. Find the file named UnrealVersionSelector-Win64-Shippping.exe in the UnrealEngine/Engine/Binaries/Win64/ folder and run it. Now, youÔÇÖll be able to double-click .uproject files to load the project, or right click them to quickly update Visual Studio files.

This should now allow you to right click on the uproject file to bring up the menu.

when you click switch engine versions make sure that your source build version of the engine is selected in the drop down box and click ok.

File:Selectsource.png

this should automatically regenerate the visual studio solution project files . if it does not then it means your files are already up to date but just to be safe you can right click the uproject file again and click "generate visual studio project files"

Building the server

next open up the visual studio project solution and allow it to fully load until it says ready.

File:Testsolution.png

go up to the drop down box and in the menu this time select DEVELOPMENT EDITOR

File:Developmenteditor.png

then same as before go to the solution explorer and right click and click build

File:Buildserver.png

again depending on youre computer this can take a long time to complete.

once this is done go back to the menu and in the drop down box this time select DEVELOPMENT SERVER

File:Development server.png

then same as before go to the solution explorer and right click and click build

File:Buildserver.png

again depending on your computer this can take a long time to complete.

once the server is built if you go into your project folder again then click binaries, win64 and you should have the server files in there like this

File:Serverfiles.png

Fixing the lighting swarm error

With source built unreal when you go to build the lighting it is common for the following error to occur and it took me forever to find the solution so i am including it here to save you guys the headache.

File:Swarm errorr.png

so what you do is in your solution explorer in visual studio scroll down until you see "unreal lightmass"

File:Lightmass.png

and again like before right click it and click build.

when it has finished close visual studio and now the swarm bug error should be fixed.

Video Guide

Prepare the project for packaging

now open up your project again by clicking on the uproject file.

ok so the first thing we need to do is under the content folder is add two new folders . one called maps, the other blueprints.

File:Folder structure.png

then we need to go down to where the third person example map is stored and move it into your newly created map folder like so.

File:Maps.png

rename this to test level or whatever you like. this will be the level that the player loads into the server on and plays the game .

as of engine versions 4.14+ whenever you make a new map you must open the map and then click on build so that it generates the correct mapBuildDataRegistry Files for it. once this is done then click save all.

now we need to create 2 more additional maps. so go up to file, then new level and select the empty map level. name this first level entry map, and the second level transition map. like so

File:Mapfiles.png

again dont forget to build each time on the new map to make sure the data is saved correctly.

open up the entry level map and go up to blueprints and open the level blueprint

File:Openlevel.png

in this blueprint drag off from begin play and find the open level node. in the level name set the parameter to 127.0.0.1 this is your local ip address.

File:Ip.png

compile and save and close the blueprint.

finally open up the test level map and just click on the default character that is in the map and just delete him otherwise when you join the server you will end up with duplicated characters.

File:Testlevel.png

now we need to set the project settings up

so open up the project settings and then go to maps and modes.

set the editor startup map to entry

set the game default map to entry

set the transition map to transition

set the server default map to test level

like so

File:Mapsetup.png

Setup packaging settings

go to file, packaging, packaging settings

File:PackagingSettings.png

in the packaging settings scroll down till you find the section list of maps to include in a packaged build . click on the + sign to add 3 elements to the array. one for each map you have in the project. then browse to your map folder and add each of your 3 maps to the array like so

File:Addmaps.png

now close the settings and package the project.

File:Packageproject.png

Congratulations you have now packaged your project

Launching and joining the dedicated server

Copy the server executable

go to your project folder, then binaries, win 64, and find the file called "yourProjectNameServer.exe" and right click it and copy it.

File:Copyproject.png

next go to your packaged game location. then WindowsNoEditor, then the name of your project, binaries, win64, and paste in the server.exe like so.

File:Projectbinaries.png

Create the server shortcut and setup log options

now take the server file and create a shortcut to it. then rename it to match whatever you called your map inside the project . in my case i called it test level so my shortcut will look like this

File:Shortcut.png

now right click this shortcut and go to properties

File:Properties.png

at the end of the target path simply add -log like so

File:Targetpath.png

and click ok

Launch and test the server

Now we are ready to launch the dedicated server and test level.

double click the server shortcut you just modified

if all goes well you should see a command window open and the server will launch itself

File:Serverlog.png

here you can see the ip address of the computer hosting the server, you can see the server is listening on port 7777 which is the default unreal port, and it has loaded up the test level map as we set out in our project.

Your server is now running all that's left now is to click the project.exe to join the server.

in the logs if all is well you will see that a client requested to join the server and then at the bottom you should see join succeeded: 256

this means the player has successfully joined the dedicated server.

File:Joinsuccess.png

if you were to launch another game exe you would now see another login success and the number would now be :257

like so

File:257.png

congratulations you are now hosting a dedicated server on your own computer and have two players joined that can run around and see each other

File:Yay.png

to properly close down the server in the command window press ctrl c. alternatively you can press the x on the log window or failing that you can ctr alt delete and kill any unreal processes that are running. but the best method is to use ctrl c

Notes

Allowing friends to join over internet

if you want to allow friends to join your games etc then simply go back to your project and on the entry level, open the level blueprint and instead of using your local ip address, input your real public ip address.

File:Ip.png

to find this simply type in to google "what is my ip" . or use an ip address finding program etc.

also remember that when you make changes in the game you need to repackage the game . so once you change the ip address to your real public ip make sure to repackage the game before you send it to your friends.

also you might need to rebuild the server binaries in visual studio.

once package is complete then zip up the whole windows no editor game folder and send it to your friends.

start the server your end , then get the friends to open the game executable and join your game.

if your friends are unable to join your game it will be because you do not have the ports forwarded and setup properly on your router, and you may need to set up a static ip address.

Hosting on a virtual server

log into your virtual server, open up the internet and download the game package. unzip it and then launch the server shortcut as normal.

Creating additional maps and joining different maps

Enabling Physics

Not sure if this is still relevant in engine 4.14+ but I've left it here just in case. from original wiki authors.

As of 4.4.3, if you're replicating actors whose movement depends on simulated physics, you'll need to set their SkeletalMeshComponent.bEnablePhysicsOnDedicatedServer property to true. The standalone dedicated servers return true to IsRunningDedicatedServer(), which results in prevention of physics simulations for SkeletalMeshComponents that do not explicitly set the bEnablePhysicsOnDedicatedServer property. Thanks to user HateDread for pointing this out for me.

Details:

Commit that fixes this:

Sources & Further Reading

Original guide: Legacy/Dedicated Server Guide (Windows & Linux)

Video: