MAXNEARZEROVELOCITYSQUARED

MAXNEARZEROVELOCITYSQUARED

#Overview

name: MAXNEARZEROVELOCITYSQUARED

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

It is referenced in 3 C++ source files.

#Summary

#Usage in the C++ source code

The purpose of MAXNEARZEROVELOCITYSQUARED is to define a threshold for determining when a network-replicated velocity is considered to be effectively zero. This setting is used in the network movement and replication system of Unreal Engine 5.

MAXNEARZEROVELOCITYSQUARED is primarily used by the GameNetworkManager subsystem, which is part of the Engine module. This subsystem is responsible for managing network-related aspects of gameplay, particularly movement replication and client-server synchronization.

The value of this variable is set in two places:

  1. It’s declared as a UPROPERTY with the GlobalConfig flag in the AGameNetworkManager class, which means it can be set in the engine’s configuration files.
  2. It’s given a default value of 9.0f in the AGameNetworkManager constructor.

This variable interacts with the NetworkVelocityNearZero function, which uses MAXNEARZEROVELOCITYSQUARED to determine if a given velocity is considered near zero for networking purposes.

Developers should be aware that this variable affects how the engine determines whether an object’s velocity is significant enough to be replicated over the network. A higher value will result in more velocities being considered “near zero” and potentially not replicated, which can save bandwidth but may reduce movement precision for networked objects.

Best practices when using this variable include:

  1. Carefully consider the implications of changing this value, as it can affect network performance and gameplay feel.
  2. Test thoroughly with various network conditions when adjusting this value to ensure it doesn’t introduce unexpected behavior.
  3. Consider the types of movements in your game when setting this value. Fast-paced games might benefit from a lower value for more precise movement replication.
  4. Use this in conjunction with other network settings to achieve the right balance between network performance and gameplay accuracy.

#Setting Variables

#References In INI files

Location: <Workspace>/Engine/Config/BaseGame.ini:25, section: [/Script/Engine.GameNetworkManager]

#References in C++ code

#Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Classes/GameFramework/GameNetworkManager.h:118

Scope (from outer to inner):

file
class        class AGameNetworkManager : public AInfo

Source code excerpt:

	/** MAXNEARZEROVELOCITYSQUARED is the square of the max velocity that is considered zero (not corrected) in net play */
	UPROPERTY(GlobalConfig)
	float MAXNEARZEROVELOCITYSQUARED;

	/** CLIENTADJUSTUPDATECOST is the bandwidth cost in bytes of sending a client adjustment update. 180 is greater than the actual cost, but represents a tweaked value reserving enough bandwidth for
	other updates sent to the client.  Increase this value to reduce client adjustment update frequency, or if the amount of data sent in the clientadjustment() call increases */
	UPROPERTY(GlobalConfig)
	float CLIENTADJUSTUPDATECOST;

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/GameNetworkManager.cpp:25

Scope (from outer to inner):

file
function     AGameNetworkManager::AGameNetworkManager

Source code excerpt:

	MoveRepSize = 42.0f;
	MAXPOSITIONERRORSQUARED = 3.0f;
	MAXNEARZEROVELOCITYSQUARED = 9.0f;
	CLIENTADJUSTUPDATECOST = 180.0f;
	MAXCLIENTUPDATEINTERVAL = 0.25f;
	MaxClientForcedUpdateDuration=1.0f;
	ServerForcedUpdateHitchThreshold = 0.150f;
	ServerForcedUpdateHitchCooldown = 0.100f;
	MaxMoveDeltaTime = 0.125f;

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/GameNetworkManager.cpp:168

Scope (from outer to inner):

file
function     bool AGameNetworkManager::NetworkVelocityNearZero

Source code excerpt:

bool AGameNetworkManager::NetworkVelocityNearZero(FVector InVelocity) const
{
	return InVelocity.SizeSquared() < GetDefault<AGameNetworkManager>(GetClass())->MAXNEARZEROVELOCITYSQUARED;
}