Packaged client runs with wrong NetMode

I have some extra code in my GameState that is only supposed to run on server/standalone guarded by
if (GetNetMode() < ENetMode::NM_Client)
When I PIE everything is fine and this part of code is not invoked on the client. Today I packaged client and server and tried to run them. Server starts fine and has NM_DedicatedServer when passing the if above… Client for some reason has NM_Standalone at the if, and enters the wrong path, eventually crashing because it has no server-only datatables that are loaded there.

Client is packaged using xxClient.Target.cs:

using UnrealBuildTool;
using System.Collections.Generic;

public class xxClientTarget : TargetRules
	public xxClientTarget( TargetInfo Target) : base(Target)
		IncludeOrderVersion = EngineIncludeOrderVersion.Unreal5_1;
		Type = TargetType.Client;
		DefaultBuildSettings = BuildSettingsVersion.V2;
		ExtraModuleNames.AddRange( new string[] { "xx" } );

Not sure why it works fine in PIE, maybe I am doing it at the wrong point in the startup code… The if above is in my GameState::ReceivedGameModeClass(), and I call the Super after I do my stuff…

Is client supposed to start with NM_Standalone and only switch to NM_Client after it is connected to the server? And in PIE it does not happen because the connection to the server is immediate?


Game or client always load the initial entry map in Standalone mode, which is where you usually do your main menu.

Dedicated servers start in server mode directly because they have the -server command-line argument builtin.

You can do something similar on client with a shortcut such as MyGame.exe in which case the client should connect directly to server. But I’m not even sure, it might still load a temporary Standalone world while connecting…

Be sure :slight_smile: tried it and it loads straight as client. thanks.

Found one caveat though: when package shipping build it breaks in 5.2 because UGameInstance::StartGameInstance() treats it as a map override and disallows it.