Dedicated Server Guide (Windows)

Guide on building Unreal Engine and project in the Dedicated server configuration.

Updated 9 months ago Edit Page Revisions

In order to build dedicated servers for Windows, you need a source build of Unreal Engine. Check out:

UE 5.0

https://docs.unrealengine.com/5.2/en-US/setting-up-dedicated-servers-in-unreal-engine/

UE4.26

https://docs.unrealengine.com/4.26/en-US/InteractiveExperiences/Networking/HowTo/DedicatedServers/

It's also not possible to build an engine from scratch with the blueprint-only project. You need to set up C++ project modules and compile your own engine.

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

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 the Visual Studio before closing. it may prompt you to save just click OK.

Setting up the server Target.cs

Open up the previously created project folder from the file explorer inside there will be a folder called Source.

File:Sourcefolder.png

Create a new Target.cs name in format \\\[ProjectName\\\]Server.Target.cs.

File:Testserver.png

Paste below snipper to your new file. Simply replace "MyGame" with your project codename.

using UnrealBuildTool;
using System.Collections.Generic;

[SupportedPlatforms(UnrealPlatformClass.Server)]

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

    public override void SetupBinaries(TargetInfo Target, ref List`` OutBuildBinaryConfigurations, ref List`` OutExtraModuleNames )
    {
        OutExtraModuleNames.Add("MyGame");
    }
}
using UnrealBuildTool;
using System.Collections.Generic;

[SupportedPlatforms(UnrealPlatformClass.Server)]

public class MyGameServerTarget : TargetRules
{
    public MyGameServerTarget(TargetInfo Target) : base(Target)
    {
        Type = TargetType.Server;
        ExtraModuleNames.Add("MyGame");
    }
}
// Fill out your copyright notice in the Description page of Project Settings.

using UnrealBuildTool;
using System.Collections.Generic;

public class MyGameServerTarget : TargetRules
{
    public MyGameServerTarget (TargetInfo Target) : base(Target)
    {
        Type = TargetType.Server;
        DefaultBuildSettings = BuildSettingsVersion.V2;

        ExtraModuleNames.AddRange( new string[] { "MyGame" } );
    }
}

Switch Unreal Engine versions

Right-click the uproject file and when the menu pops up select "Switch Unreal Engine version...".

File:Build server.png

Select your source build location in the drop-down and click OK.

File:Selectsource.png

You need to regenerate project files every time after adding, renaming or removing a source file. Right-click the .uproject file and choose Generate Visual Studio project files. Do it now.

Skipping this step here would cause that VS solution won't include your new server Target.cs and server won't even start compiling. You could just get a confusing "build succeeded" message just after starting a build.

Building the server

Open up the Visual Studio project solution and allow it to fully load until it says ready.

File:Testsolution.png

Select "Development Editor" configuration.

File:Developmenteditor.png

Go to the solution explorer, right-click on your project item and click Build.

File:Buildserver.png

Compilation times depend on your hardware configuration: CPU, RAM and Drive Speed.

Once this is done, go back to the menu and select "Development Server" configuration.

File:Development server.png

Call Build one more time.

File:Buildserver.png

Once the compilation succeeded, go into your project folder. Open the Binaries/Win64 folder and you should see server binaries files there.

File:Serverfiles.png

Compile additional programs.

While compiling the engine on your own, you also need to compile additional programs that come with Unreal Engine editor. Some of them are included in the editor build, but not all of them, i.e. Lightmass.

File:Swarm errorr.png

So whatever program you need, locate it on the Programs list in solution and compile it.

File:Lightmass.png

Prepare basic maps

Open up editor and create a basic set of maps - if you don't have it already.

Update guide using a bit more intuitive map names.

TestLevel would your default Server map, while EntryMap is your default Client map.

File:Mapfiles.png

Load the EntryMap and open its level blueprint.

File:Openlevel.png

Add call to "Open Level" function which will connect your client to the dedicated server on the same machine.

File:Ip.png

Compile and save the level blueprint.

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

File:Testlevel.png

Open Project Settings, find Maps and Modes section.

  • Set the editor startup map to EntryMap

  • Set the game default map to EntryMap

  • Set the transition map to TransitionMap

  • Set the server default map to TestLevel

File:Mapsetup.png

Setup packaging settings

Go to "File > Package Project > Packaging Settings...".

File:PackagingSettings.png

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. Browse to your map folder and add each of your 3 maps to the array.

File:Addmaps.png

Now close the settings and package the project for the platform of your choice.

File:Packageproject.png

Launching and joining the dedicated server

Copy the server executable

Go to your project folder, then Binaries, Win64, and find the file called "MyGameServer.exe" and right click it and copy it.

File:Copyproject.png

Go to your packaged game location. then WindowsNoEditor, then the name of your project, Binaries, Win64, and paste in the MyGameServer.exe.

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. I called it "testLevel" so my shortcut looks like this.

File:Shortcut.png

Right-click this shortcut and go to "Properties".

File:Properties.png

At the end of the target path simply add -log.

File:Targetpath.png

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 MyGame.exe to join the server.

In the log 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 instance you would now see another login success and the number would now be 257.

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 Ctrl+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

The method below is fine for the one-time test, but the server IP address should be never set statically in blueprints. This part of the guide needs to be updated.

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

File:Ip.png

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.

Once the package is complete then zip up the whole WindowsNoEditor game folder and send it to your friends. Start the server on 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 set up properly on your router, and you may need to set up a static IP address.

Original guide

Legacy/Dedicated Server Guide (Windows & Linux)