net.PingUsePacketRecvTime

net.PingUsePacketRecvTime

#Overview

name: net.PingUsePacketRecvTime

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.PingUsePacketRecvTime is to control how ping is calculated in Unreal Engine’s networking system. Specifically, it determines whether to use the OS or Receive Thread packet receive time for calculating ping, which excludes frame time from the calculation.

This setting variable is primarily used by 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 is a core part of Unreal Engine’s networking implementation.

The value of this variable is set using a console variable (CVar) system. It’s initialized with a default value of 0 in the C++ code, but can be changed at runtime through console commands or configuration files.

The associated variable CVarPingUsePacketRecvTime directly interacts with net.PingUsePacketRecvTime. They share the same value and purpose, with CVarPingUsePacketRecvTime being the C++ representation of the console variable.

Developers must be aware that enabling this variable (setting it to a non-zero value) will change how ping is calculated. Instead of including frame time in the ping calculation, it will use the packet receive time from either the OS or the Receive Thread. This can provide a more accurate representation of actual network latency by excluding processing time on the game thread.

Best practices when using this variable include:

  1. Consider enabling it in scenarios where you need a more accurate representation of network latency, especially in multiplayer games where precise timing is crucial.
  2. Be consistent in its usage across development and production environments to ensure consistent behavior.
  3. Monitor its effects on your game’s networking behavior and performance metrics.
  4. Use it in conjunction with other networking diagnostics tools to get a comprehensive view of your game’s network performance.

Regarding the associated variable CVarPingUsePacketRecvTime:

The purpose of CVarPingUsePacketRecvTime is identical to net.PingUsePacketRecvTime, as it’s the C++ representation of the console variable.

It’s used within the UNetConnection::ReadPacketInfo function to determine whether to use the OS receive time for packet timing calculations. This function is a key part of Unreal Engine’s network packet processing pipeline.

The value of CVarPingUsePacketRecvTime is set through the console variable system and can be accessed in C++ code using the GetValueOnAnyThread() method.

Developers should be aware that this variable is accessed in a multithreaded context (note the use of GetValueOnAnyThread()), so any changes to its value may not immediately affect all threads.

Best practices for CVarPingUsePacketRecvTime include:

  1. Use it for runtime configuration of networking behavior, allowing for easy testing and adjustment of ping calculation methods.
  2. Consider exposing this setting in your game’s networking options if you want to give players or server administrators control over ping calculation methods.
  3. Be cautious when changing this value during gameplay, as it could affect the consistency of network behavior.

#References in C++ code

#Callsites

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

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

Scope: file

Source code excerpt:

	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
static TAutoConsoleVariable<int32> CVarPingDisplayServerTime(TEXT("net.PingDisplayServerTime"), 0,
	TEXT("Show server frame time. Not available in shipping builds."));
#endif

#Associated Variable and Callsites

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

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

Scope: file

Source code excerpt:

	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
static TAutoConsoleVariable<int32> CVarPingDisplayServerTime(TEXT("net.PingDisplayServerTime"), 0,
	TEXT("Show server frame time. Not available in shipping builds."));
#endif

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

Scope (from outer to inner):

file
function     bool UNetConnection::ReadPacketInfo

Source code excerpt:

		FTimespan& RecvTimespan = LastOSReceiveTime.Timestamp;

		if (!RecvTimespan.IsZero() && Driver != nullptr && CVarPingUsePacketRecvTime.GetValueOnAnyThread())
		{
			if (bIsOSReceiveTimeLocal)
			{
				PacketReceiveTime = RecvTimespan.GetTotalSeconds();
			}
			else if (ISocketSubsystem* SocketSubsystem = Driver->GetSocketSubsystem())