net.NetPingEnabled

net.NetPingEnabled

#Overview

name: net.NetPingEnabled

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.NetPingEnabled is to control the activation of the NetPing ping handling interface in Unreal Engine’s networking system. This setting is used for centralized ping tracking and ICMP/UDP ping functionality.

This setting variable is primarily used by the networking subsystem of Unreal Engine, specifically within the NetPing module. Based on the callsites, it’s part of the Engine module and is used in the Net namespace.

The value of this variable is set through a console variable (CVar) system. It’s defined as a TAutoConsoleVariable with an initial value of 0, which means it’s off by default. The value can be changed at runtime through console commands or programmatically.

The CVarNetPingEnabled interacts with another console variable, CVarNetPingTypes, which specifies the types of pings to enable and their averaging method.

Developers must be aware that this variable accepts four different values: 0 - Off (default) 1 - Enabled for client 2 - Enabled for server and client 3 - Enabled for server only

When using this variable, developers should consider the network architecture of their game (client-server or peer-to-peer) and enable it accordingly. It’s important to note that enabling this feature may have performance implications, so it should be used judiciously.

Best practices when using this variable include:

  1. Only enable it when necessary for network diagnostics or when implementing features that require precise ping information.
  2. Consider the security implications of exposing ping information, especially on the server side.
  3. Test thoroughly with different network conditions to ensure it doesn’t negatively impact game performance.

Regarding the associated variable CVarNetPingEnabled:

The purpose of CVarNetPingEnabled is the same as net.NetPingEnabled, as they are essentially the same variable. CVarNetPingEnabled is the C++ representation of the console variable net.NetPingEnabled.

This variable is used within the FNetPing::CreateNetPing function to determine whether to create a NetPing instance based on the current network role (client or server) and the value of the variable.

The value of CVarNetPingEnabled is retrieved using the GetValueOnAnyThread() method, which suggests it can be accessed from multiple threads.

Developers should be aware that changes to this variable at runtime will affect the creation of new NetPing instances but may not affect existing ones.

Best practices for CVarNetPingEnabled include:

  1. Use it in conjunction with appropriate error handling and fallback mechanisms in case the NetPing functionality is disabled.
  2. Consider exposing a game-specific setting that wraps this CVar to give more control to end-users or server administrators.
  3. Log changes to this variable’s value for debugging purposes, especially in networked environments.

#References in C++ code

#Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/Net/NetPing.cpp:31

Scope (from outer to inner):

file
namespace    UE::Net

Source code excerpt:


static TAutoConsoleVariable<int32> CVarNetPingEnabled(
	TEXT("net.NetPingEnabled"), 0,
	TEXT("Whether or not the NetPing ping handling interface is enabled. Used for centralized ping tracking, and ICMP/UDP ping. ")
	TEXT("(Valid values: 0 = Off, 1 = Enabled for client, 2 = Enabled for server and client, 3 = Enabled for server only)"));

static TAutoConsoleVariable<FString> CVarNetPingTypes(
	TEXT("net.NetPingTypes"), TEXT(""),
	TEXT("A comma-delimited list of EPingType pings to enable, and (optionally) the EPingAverageType averaging to apply to the ping ")

#Associated Variable and Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/Net/NetPing.cpp:30

Scope (from outer to inner):

file
namespace    UE::Net

Source code excerpt:

// CVars

static TAutoConsoleVariable<int32> CVarNetPingEnabled(
	TEXT("net.NetPingEnabled"), 0,
	TEXT("Whether or not the NetPing ping handling interface is enabled. Used for centralized ping tracking, and ICMP/UDP ping. ")
	TEXT("(Valid values: 0 = Off, 1 = Enabled for client, 2 = Enabled for server and client, 3 = Enabled for server only)"));

static TAutoConsoleVariable<FString> CVarNetPingTypes(
	TEXT("net.NetPingTypes"), TEXT(""),

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/Net/NetPing.cpp:309

Scope (from outer to inner):

file
namespace    UE::Net
function     TPimplPtr<FNetPing> FNetPing::CreateNetPing

Source code excerpt:

	if (const UNetDriver* Driver = InOwner != nullptr ? InOwner->Driver : nullptr)
	{
		const int32 EnabledVal = CVarNetPingEnabled.GetValueOnAnyThread();
		const bool bEnabledForClient = EnabledVal == 1 || EnabledVal == 2;
		const bool bEnabledForServer = EnabledVal == 2 || EnabledVal == 3;
		const bool bIsServer = Driver->IsServer();
		const bool bIsGameDriver = (Driver->NetDriverName == NAME_GameNetDriver || Driver->NetDriverName == NAME_PendingNetDriver);

		if (bIsGameDriver && ((!bIsServer && bEnabledForClient) || (bIsServer && bEnabledForServer)))