p.NetForceClientAdjustmentPercent

p.NetForceClientAdjustmentPercent

#Overview

name: p.NetForceClientAdjustmentPercent

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.NetForceClientAdjustmentPercent is to simulate network errors and test client correction code in the Character Movement Component of Unreal Engine 5.

This setting variable is primarily used in the Character Movement system, specifically within the UCharacterMovementComponent. It’s part of the Engine module and is used for networking and movement correction testing.

The value of this variable is set through the Unreal Engine console variable system. It’s defined as an FAutoConsoleVariableRef, which means it can be adjusted at runtime through console commands or configuration files.

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

Developers must be aware that this variable is only active in non-shipping and non-test builds (development builds). It’s marked with the ECVF_Cheat flag, indicating it’s for testing purposes and should not be used in production environments.

Best practices when using this variable include:

  1. Only use it for testing and debugging client correction code.
  2. Be cautious when setting high values, as it can significantly impact gameplay and network performance.
  3. Remember to disable or set it to 0 before building for release.

Regarding the associated variable NetForceClientAdjustmentPercent:

Its purpose is to store the actual value used by the CharacterMovementComponent to force client adjustments for testing purposes.

It’s used within the UCharacterMovementComponent::ServerCheckClientError function to randomly determine if a client error should be simulated, regardless of the actual error state.

The value is set directly by the console variable p.NetForceClientAdjustmentPercent.

Developers should be aware that this variable is only used in development builds and its behavior directly affects the ServerCheckClientError function, which is crucial for network movement correction.

Best practices include using this variable in conjunction with logging (as seen in the code) to track when forced client adjustments occur during testing.

#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:357

Scope (from outer to inner):

file
namespace    CharacterMovementCVars

Source code excerpt:

	static float NetForceClientAdjustmentPercent = 0.f;
	FAutoConsoleVariableRef CVarNetForceClientAdjustmentPercent(
		TEXT("p.NetForceClientAdjustmentPercent"),
		NetForceClientAdjustmentPercent,
		TEXT("Percent of ServerCheckClientError checks to return true regardless of actual error.\n")
		TEXT("Useful for testing client correction code.\n")
		TEXT("<=0: Disable, 0.05: 5% of checks will return failed, 1.0: Always send client adjustments"),
		ECVF_Cheat);

#Associated Variable and Callsites

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

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

Scope (from outer to inner):

file
namespace    CharacterMovementCVars

Source code excerpt:

#if !(UE_BUILD_SHIPPING || UE_BUILD_TEST)

	static float NetForceClientAdjustmentPercent = 0.f;
	FAutoConsoleVariableRef CVarNetForceClientAdjustmentPercent(
		TEXT("p.NetForceClientAdjustmentPercent"),
		NetForceClientAdjustmentPercent,
		TEXT("Percent of ServerCheckClientError checks to return true regardless of actual error.\n")
		TEXT("Useful for testing client correction code.\n")
		TEXT("<=0: Disable, 0.05: 5% of checks will return failed, 1.0: Always send client adjustments"),
		ECVF_Cheat);

	static float NetForceClientServerMoveLossPercent = 0.f;

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

Scope (from outer to inner):

file
function     bool UCharacterMovementComponent::ServerCheckClientError

Source code excerpt:


#if !(UE_BUILD_SHIPPING || UE_BUILD_TEST)
		if (CharacterMovementCVars::NetForceClientAdjustmentPercent > UE_SMALL_NUMBER)
		{
			if (RandomStream.FRand() < CharacterMovementCVars::NetForceClientAdjustmentPercent)
			{
				UE_LOG(LogNetPlayerMovement, VeryVerbose, TEXT("** ServerCheckClientError forced by p.NetForceClientAdjustmentPercent"));
				return true;
			}
		}
#endif