net.PingExcludeFrameTime

net.PingExcludeFrameTime

#Overview

name: net.PingExcludeFrameTime

The value of this variable can be defined or overridden in .ini config files. 1 .ini config file referencing this setting variable.

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

It is referenced in 5 C++ source files.

#Summary

#Usage in the C++ source code

The purpose of net.PingExcludeFrameTime is to provide an option for calculating network ping by excluding game frame times from the total round-trip time (RTT). This setting is used in the networking system of Unreal Engine 5, specifically for more accurate ping measurements.

This setting variable is primarily used in the networking subsystem of Unreal Engine, particularly within the NetConnection module. It’s referenced in the Engine/Source/Runtime/Engine/Private/NetConnection.cpp file, which handles network connections and related operations.

The value of this variable is set through a console variable (CVar) named CVarPingExcludeFrameTime. It’s initialized with a default value of 0, meaning frame times are included in ping calculations by default.

The associated variable CVarPingExcludeFrameTime directly interacts with net.PingExcludeFrameTime. They share the same value and purpose.

Developers should be aware that:

  1. This variable affects how ping is calculated, which can impact perceived network performance.
  2. It’s a boolean value (0 or 1), where 1 excludes frame times from ping calculations.
  3. Changing this value can affect gameplay and networking diagnostics.

Best practices when using this variable include:

  1. Use it when you want to measure actual network latency without the influence of client-side frame processing time.
  2. Consider enabling it (set to 1) in scenarios where you need to isolate network performance from client performance.
  3. Be consistent in its usage across development and testing to ensure comparable results.

Regarding the associated variable CVarPingExcludeFrameTime:

#Setting Variables

#References In INI files

Location: <Workspace>/Projects/Lyra/Config/DefaultEngine.ini:149, section: [ConsoleVariables]

#References in C++ code

#Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/NetConnection.cpp:56

Scope: file

Source code excerpt:

LLM_DEFINE_TAG(NetConnection, NAME_None, TEXT("Networking"), GET_STATFNAME(STAT_NetConnectionLLM), GET_STATFNAME(STAT_NetworkingSummaryLLM));

static TAutoConsoleVariable<int32> CVarPingExcludeFrameTime(TEXT("net.PingExcludeFrameTime"), 0,
	TEXT("If true, game frame times are subtracted from calculated ping to approximate actual network ping"));

static TAutoConsoleVariable<int32> CVarPingUsePacketRecvTime(TEXT("net.PingUsePacketRecvTime"), 0,
	TEXT("Use OS or Receive Thread packet receive time, for calculating the ping. Excludes frame time."));

#if !UE_BUILD_SHIPPING

#Associated Variable and Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/NetConnection.cpp:56

Scope: file

Source code excerpt:

LLM_DEFINE_TAG(NetConnection, NAME_None, TEXT("Networking"), GET_STATFNAME(STAT_NetConnectionLLM), GET_STATFNAME(STAT_NetworkingSummaryLLM));

static TAutoConsoleVariable<int32> CVarPingExcludeFrameTime(TEXT("net.PingExcludeFrameTime"), 0,
	TEXT("If true, game frame times are subtracted from calculated ping to approximate actual network ping"));

static TAutoConsoleVariable<int32> CVarPingUsePacketRecvTime(TEXT("net.PingUsePacketRecvTime"), 0,
	TEXT("Use OS or Receive Thread packet receive time, for calculating the ping. Excludes frame time."));

#if !UE_BUILD_SHIPPING

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/NetConnection.cpp:2568

Scope (from outer to inner):

file
function     void UNetConnection::WriteDummyPacketInfo

Source code excerpt:

#endif

		const uint8 bHasServerFrameTime = Driver->IsServer() ? bLastHasServerFrameTime : (CVarPingExcludeFrameTime.GetValueOnGameThread() > 0 ? 1u : 0u);
		Writer.WriteBit(bHasServerFrameTime);

		if (bHasServerFrameTime && Driver->IsServer())
		{
			uint8 DummyFrameTimeByte(0);
			Writer << DummyFrameTimeByte;

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/NetConnection.cpp:2636

Scope (from outer to inner):

file
function     void UNetConnection::WriteFinalPacketInfo

Source code excerpt:

	// Write server frame time
	{
		const uint8 bHasServerFrameTime = Driver->IsServer() ? bLastHasServerFrameTime : (CVarPingExcludeFrameTime.GetValueOnGameThread() > 0 ? 1u : 0u);
		Writer.WriteBit(bHasServerFrameTime);

		if (bHasServerFrameTime && Driver->IsServer())
		{
			// Write data used to calculate link latency
			uint8 FrameTimeByte = FMath::Min(FMath::FloorToInt(FrameTime * 1000), 255);

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/NetConnection.cpp:2726

Scope (from outer to inner):

file
function     bool UNetConnection::ReadPacketInfo

Source code excerpt:


		// Use FApp's time because it is set closer to the beginning of the frame - we don't care about the time so far of the current frame to process the packet
		const bool bExcludeFrameTime = !!CVarPingExcludeFrameTime.GetValueOnAnyThread();
		const double CurrentTime	= (PacketReceiveTime != 0.0 ? PacketReceiveTime : FApp::GetCurrentTime());
		const double RTT			= (CurrentTime - OutLagTime[Index]);
		const double RTTExclFrame	= RTT - (bExcludeFrameTime ? ServerFrameTime : 0.0);
		const double NewLag			= FMath::Max(RTTExclFrame, 0.0);

		//UE_LOG( LogNet, Warning, TEXT( "Out: %i, InRemote: %i, Saturation: %f" ), OutBytesPerSecondHistory[Index], RemoteInKBytesPerSecond, RemoteSaturation );