Here's a step-by-step example of running a dedicated server instead of a listen server for an Unreal Engine game. We'll cover:
- Building the Dedicated Server Executable
- Configuring the Server
- Launching the Dedicated Server
- Connecting Clients to the Dedicated Server
- Key Differences from a Listen Server
Prerequisites:
- Unreal Engine 4.27 or later (UE5 works similarly).
- A multiplayer-capable Unreal project (e.g., a third-person shooter or any game with networking).
- Basic understanding of Unreal's Blueprints or C++ for game logic.
Step 1: Build the Dedicated Server Executable
- Open Your Project in the Unreal Editor.
- Go to Edit > Project Settings.
- Navigate to Packaging under Project.
- Configure the following:
- Build Configuration: Set to Shipping (optimized for performance).
- Additional Build Arguments: Add
-DedicatedServer (critical for creating a dedicated server build).
- Package Game: Check this box.
- Platform: Choose Windows (or your target platform).
- Architecture: Select x64.
- Click Package Project.
Unreal Engine will generate a dedicated server executable in:
YourProject/Saved/StagedBuilds/Windows/x64/YourProjectServer/YourProjectServer.exe
Step 2: Configure the Server (Server.ini)
- In your project's root directory, navigate to:
YourProject/Config/
- Create a file named
DefaultEngine.ini (or edit the existing one).
- Add the following configuration to define the server settings:
[/Script/Engine.GameEngine]
+NetDriverDefinitions=(DefName="GameNetDriver",DriverClassName="/Script/OnlineSubsystemUtils.IpNetDriver",DriverClassNameFallback="/Script/OnlineSubsystemUtils.IpNetDriver")
[/Script/OnlineSubsystemUtils.IpNetDriver]
NetServerMaxTickRate=60 ; Server tick rate
MaxClientRate=100000 ; Max bandwidth for clients
MaxInternetClientRate=100000
[/Script/Engine.GameSession]
MaxPlayers=16 ; Maximum players allowed on the server
[/Script/Engine.Engine]
+MapsToCook=YourGameMap ; The map the server loads at startup
- Optional: If you want RCON (Remote Console) for admin access:
[/Script/OnlineSubsystemUtils.IpNetDriver]
bEnabledRCON=true
RCONPassword="YourSecurePassword"
Step 3: Launch the Dedicated Server
- Open a Command Prompt or Terminal.
- Navigate to the directory where your server executable is located:
cd YourProject/Saved/StagedBuilds/Windows/x64/YourProjectServer/
- Run the server with the following command:
YourProjectServer.exe YourGameMap?listen -Port=7777 -log
Explanation:
YourGameMap: The map to load (e.g., LobbyMap or GameMap).
?listen: Tells the server to start listening for connections.
-Port=7777: The port the server listens on (default is 7777).
-log: Outputs server logs to the console (useful for debugging).
Example Command:
YourProjectServer.exe LobbyMap?listen -Port=7777 -MaxPlayers=16 -log
The server will start, load the map, and begin listening for incoming connections.
Step 4: Connect Clients to the Dedicated Server
Clients can connect in two ways:
Method 1: Via the Unreal Editor (for testing)
- Open your project in the Unreal Editor.
- Press ~ (tilde key) to open the Console.
- Type:
open <ServerIP>:7777
Replace <ServerIP> with:
127.0.0.1 (if the server is on the same machine).
- Your local IP (e.g.,
192.168.1.100) if the server is on another machine in your LAN.
- Your public IP (e.g.,
203.0.113.45) if connecting over the internet (ensure port forwarding is set up).
Example:
open 127.0.0.1:7777
Method 2: Via the Packaged Game Client
- Package your game client (without
-DedicatedServer flag).
- Launch the packaged game.
- Go to Main Menu > Connect to Server.
- Enter the server IP and port (e.g.,
127.0.0.1:7777).
Step 5: Port Forwarding (For Internet-Hosted Servers)
If the dedicated server is hosted on a home network and you want others to connect over the internet:
- Find Your Public IP:
- Configure Port Forwarding:
- Access your router’s settings (usually
192.168.1.1 or 192.168.0.1).
- Go to Port Forwarding or Virtual Servers.
- Create a rule:
- Protocol: UDP
- External Port: 7777
- Internal Port: 7777
- Internal IP: The local IP of the machine running the server (e.g.,
192.168.1.100).
- Allow Firewall Access:
- Add an exception in Windows Firewall for UDP port 7777.
Now, clients can connect using your public IP: open <YourPublicIP>:7777.
Key Differences from a Listen Server
| Feature | Listen Server | Dedicated Server |
|---|
| Process | Client and server combined in one executable. | Separate executable (-DedicatedServer flag). |
| Performance | Host player shares resources with the server. | Server runs independently; better stability. |
| Setup | Automatic (starts when a player hosts a game). | Manual launch required (Server.exe). |
| Configuration | Limited customization (relies on client settings). | Fully configurable via Server.ini and command args. |
| Internet Hosting | Requires port forwarding on the host’s machine. | Same, but often more stable due to no client overhead. |
| Cheating | Host has full access to game memory (easier to cheat). | Host only controls the server process; more secure. |
Troubleshooting Tips
- Server Not Visible: Ensure the server is running, the port is open, and firewalls are configured.
- Connection Timeout: Double-check IP and port; verify port forwarding.
- Crashes on Startup: Review server logs (
-log flag) for errors in DefaultEngine.ini or missing maps.
- Clients Can’t Connect: Ensure
MaxPlayers isn’t exceeded and the map exists on the server.
By following these steps, you’ve successfully set up a dedicated server for your Unreal Engine game. This approach scales better for larger player bases and provides a more stable hosting experience compared to listen servers. Happy developing! 🚀