net.MaxPlayersOverride

net.MaxPlayersOverride

#Overview

name: net.MaxPlayersOverride

This variable is created as a Console Variable (cvar).

It is referenced in 3 C++ source files.

#Summary

#Usage in the C++ source code

The purpose of net.MaxPlayersOverride is to provide a way to override the standard maximum player count in a game session. This setting is primarily used for testing purposes, allowing developers to simulate full server conditions without modifying the game’s default maximum player limit.

This setting variable is utilized by the Game Session subsystem within the Unreal Engine’s networking module. Specifically, it’s referenced in the GameSession.cpp file, which is part of the Engine’s runtime.

The value of this variable is set through a console variable (CVar) system. It’s defined as a TAutoConsoleVariable named CVarMaxPlayersOverride, initialized with a default value of 0.

The associated variable CVarMaxPlayersOverride interacts directly with net.MaxPlayersOverride. They share the same value and purpose.

Developers must be aware that:

  1. This variable only takes effect when its value is greater than 0.
  2. It’s intended for testing purposes and should not be used as a permanent solution for adjusting max player counts in production.
  3. Using this override bypasses any other game-specific logic for determining max players.

Best practices when using this variable include:

  1. Use it only for testing and debugging scenarios.
  2. Reset it to 0 after testing to ensure it doesn’t interfere with normal gameplay.
  3. Be cautious when using it in multiplayer testing, as it might affect other network-related behaviors.

Regarding the associated variable CVarMaxPlayersOverride: It’s a static TAutoConsoleVariable that directly represents net.MaxPlayersOverride in the code. It’s used in the AGameSession::AtCapacity function to determine if the session has reached its player limit. When CVarMaxPlayersOverride is greater than 0, it takes precedence over the standard MaxPlayers value. This allows developers to dynamically adjust the maximum player count during runtime for testing purposes.

#References in C++ code

#Callsites

This variable is referenced in the following C++ source code:

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/GameSession.cpp:18

Scope: file

Source code excerpt:

DEFINE_LOG_CATEGORY(LogGameSession);

static TAutoConsoleVariable<int32> CVarMaxPlayersOverride( TEXT( "net.MaxPlayersOverride" ), 0, TEXT( "If greater than 0, will override the standard max players count. Useful for testing full servers." ) );

APlayerController* GetPlayerControllerFromNetId(UWorld* World, const FUniqueNetId& PlayerNetId)
{
	return GetPlayerControllerFromNetId(World, FUniqueNetIdRepl(PlayerNetId.AsShared()));
}

#Associated Variable and Callsites

This variable is associated with another variable named CVarMaxPlayersOverride. They share the same value. See the following C++ source code.

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/GameSession.cpp:18

Scope: file

Source code excerpt:

DEFINE_LOG_CATEGORY(LogGameSession);

static TAutoConsoleVariable<int32> CVarMaxPlayersOverride( TEXT( "net.MaxPlayersOverride" ), 0, TEXT( "If greater than 0, will override the standard max players count. Useful for testing full servers." ) );

APlayerController* GetPlayerControllerFromNetId(UWorld* World, const FUniqueNetId& PlayerNetId)
{
	return GetPlayerControllerFromNetId(World, FUniqueNetIdRepl(PlayerNetId.AsShared()));
}

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/GameSession.cpp:357

Scope (from outer to inner):

file
function     bool AGameSession::AtCapacity

Source code excerpt:

	else
	{
		const int32 MaxPlayersToUse = CVarMaxPlayersOverride.GetValueOnGameThread() > 0 ? CVarMaxPlayersOverride.GetValueOnGameThread() : MaxPlayers;

		return ( (MaxPlayersToUse>0) && (GameMode->GetNumPlayers() >= MaxPlayersToUse) );
	}
}

void AGameSession::NotifyLogout(FName InSessionName, const FUniqueNetIdRepl& UniqueId)