p.NetForceClientServerMoveLossDuration

p.NetForceClientServerMoveLossDuration

#Overview

name: p.NetForceClientServerMoveLossDuration

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 p.NetForceClientServerMoveLossDuration is to simulate network packet loss in the character movement system for testing and debugging purposes. It specifically controls the duration for which the client will drop ServerMove calls when certain conditions are met.

This setting variable is primarily used in the Character Movement Component of Unreal Engine’s gameplay framework. It’s part of the networking and movement simulation system, which is crucial for multiplayer games and networked environments.

The value of this variable is set through the Unreal Engine’s console variable system. It’s defined as a static float within the CharacterMovementCVars namespace and is exposed as a console variable using FAutoConsoleVariableRef. This allows developers to modify its value at runtime through the console or configuration files.

The associated variable NetForceClientServerMoveLossDuration interacts directly with p.NetForceClientServerMoveLossDuration. They share the same value, with the console variable p.NetForceClientServerMoveLossDuration controlling the static variable NetForceClientServerMoveLossDuration.

Developers must be aware that this variable is intended for testing and debugging purposes only. It’s marked with ECVF_Cheat flag, indicating it should not be used in production builds or final releases. The variable simulates network issues, which can significantly affect gameplay and should be used cautiously.

Best practices when using this variable include:

  1. Only use it in development and testing environments.
  2. Use it in conjunction with other networking debugging tools to simulate various network conditions.
  3. Test with different duration values to ensure your game handles various packet loss scenarios correctly.
  4. Remember to disable or reset this variable before building for production.

Regarding the associated variable NetForceClientServerMoveLossDuration:

The purpose of NetForceClientServerMoveLossDuration is to store the actual duration value used in the character movement component’s logic. It’s the internal representation of the console variable p.NetForceClientServerMoveLossDuration.

This variable is used directly in the UCharacterMovementComponent::ReplicateMoveToServer function to determine how long the simulated packet loss should last. It affects the networking behavior of character movement, specifically the sending of ServerMove calls from the client to the server.

The value of NetForceClientServerMoveLossDuration is set indirectly through the console variable p.NetForceClientServerMoveLossDuration. They are linked through the FAutoConsoleVariableRef mechanism.

Developers should be aware that modifying NetForceClientServerMoveLossDuration directly in code won’t have the desired effect, as its value is controlled by the console variable. Always use the console variable p.NetForceClientServerMoveLossDuration to change this setting.

Best practices for NetForceClientServerMoveLossDuration are similar to those for p.NetForceClientServerMoveLossDuration, as they are essentially the same setting. Use it for testing network resilience, but ensure it’s not affecting gameplay in production builds.

#References in C++ code

#Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/Components/CharacterMovementComponent.cpp:375

Scope (from outer to inner):

file
namespace    CharacterMovementCVars

Source code excerpt:

	static float NetForceClientServerMoveLossDuration = 0.f;
	FAutoConsoleVariableRef CVarNetForceClientServerMoveLossDuration(
		TEXT("p.NetForceClientServerMoveLossDuration"),
		NetForceClientServerMoveLossDuration,
		TEXT("Duration in seconds for client to drop ServerMove calls when NetForceClientServerMoveLossPercent check passes.\n")
		TEXT("Useful for testing server force correction code.\n")
		TEXT("Duration of zero means single frame loss."),
		ECVF_Cheat);

#Associated Variable and Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/Components/CharacterMovementComponent.cpp:373

Scope (from outer to inner):

file
namespace    CharacterMovementCVars

Source code excerpt:

		ECVF_Cheat);

	static float NetForceClientServerMoveLossDuration = 0.f;
	FAutoConsoleVariableRef CVarNetForceClientServerMoveLossDuration(
		TEXT("p.NetForceClientServerMoveLossDuration"),
		NetForceClientServerMoveLossDuration,
		TEXT("Duration in seconds for client to drop ServerMove calls when NetForceClientServerMoveLossPercent check passes.\n")
		TEXT("Useful for testing server force correction code.\n")
		TEXT("Duration of zero means single frame loss."),
		ECVF_Cheat);

	static int32 VisualizeMovement = 0;

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/Components/CharacterMovementComponent.cpp:8679

Scope (from outer to inner):

file
function     void UCharacterMovementComponent::ReplicateMoveToServer

Source code excerpt:

		// Testing options: Simulated packet loss to server
		const float TimeSinceLossStart = (MyWorld->RealTimeSeconds - ClientData->DebugForcedPacketLossTimerStart);
		if (ClientData->DebugForcedPacketLossTimerStart > 0.f && (TimeSinceLossStart < CharacterMovementCVars::NetForceClientServerMoveLossDuration))
		{
			bSendServerMove = false;
			UE_LOG(LogNetPlayerMovement, Log, TEXT("Drop ServerMove, %.2f time remains"), CharacterMovementCVars::NetForceClientServerMoveLossDuration - TimeSinceLossStart);
		}
		else if (CharacterMovementCVars::NetForceClientServerMoveLossPercent != 0.f && (RandomStream.FRand() < CharacterMovementCVars::NetForceClientServerMoveLossPercent))
		{
			bSendServerMove = false;
			ClientData->DebugForcedPacketLossTimerStart = (CharacterMovementCVars::NetForceClientServerMoveLossDuration > 0) ? MyWorld->RealTimeSeconds : 0.0f;
			UE_LOG(LogNetPlayerMovement, Log, TEXT("Drop ServerMove, %.2f time remains"), CharacterMovementCVars::NetForceClientServerMoveLossDuration);
		}
		else
		{
			ClientData->DebugForcedPacketLossTimerStart = 0.f;
		}
#endif