MovementTimeDiscrepancyMaxTimeMargin

MovementTimeDiscrepancyMaxTimeMargin

#Overview

name: MovementTimeDiscrepancyMaxTimeMargin

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 MovementTimeDiscrepancyMaxTimeMargin is to set the maximum allowed time difference between the client and server in networked gameplay, specifically for movement-related operations. It helps detect and manage temporal discrepancies in multiplayer games.

This setting variable is primarily used by the Unreal Engine’s networking and movement systems, particularly within the GameFramework module. The main components that rely on this variable are the GameNetworkManager and the CharacterMovementComponent.

The value of this variable is set in the AGameNetworkManager constructor (GameNetworkManager.cpp) with a default value of 0.25 seconds. It can be modified through configuration files or at runtime, as it’s marked with the UPROPERTY(GlobalConfig) macro.

MovementTimeDiscrepancyMaxTimeMargin interacts closely with other related variables such as MovementTimeDiscrepancyMinTimeMargin, bMovementTimeDiscrepancyDetection, and bMovementTimeDiscrepancyResolution. These variables work together to manage network time discrepancies in character movement.

Developers must be aware that this variable is crucial for maintaining synchronization between client and server in multiplayer games. Setting it too high may allow cheating or unnatural movement, while setting it too low might cause unnecessary corrections and a poor player experience.

Best practices when using this variable include:

  1. Carefully tuning its value based on your game’s specific needs and network conditions.
  2. Testing thoroughly with various network conditions to ensure smooth gameplay.
  3. Considering the trade-offs between strict synchronization and player experience.
  4. Using it in conjunction with other network optimization techniques.
  5. Monitoring and logging instances where this threshold is exceeded to identify potential issues or cheating attempts.

#Setting Variables

#References In INI files

Location: <Workspace>/Engine/Config/BaseGame.ini:42, 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:201

Scope (from outer to inner):

file
class        class AGameNetworkManager : public AInfo

Source code excerpt:

	/** Maximum time client can be ahead before triggering movement time discrepancy detection/resolution (if enabled). */
	UPROPERTY(GlobalConfig)
	float MovementTimeDiscrepancyMaxTimeMargin;

	/** Maximum time client can be behind. */
	UPROPERTY(GlobalConfig)
	float MovementTimeDiscrepancyMinTimeMargin;

	/** 

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

Scope (from outer to inner):

file
function     void UCharacterMovementComponent::ProcessClientTimeStampForTimeDiscrepancy

Source code excerpt:

		if (!ServerData.bResolvingTimeDiscrepancy)
		{
			if (NewTimeDiscrepancy > GameNetworkManager->MovementTimeDiscrepancyMaxTimeMargin)
			{
				// Time discrepancy detected - client timestamp ahead of where the server thinks it should be!

				// Trigger logic for resolving time discrepancies
				if (GameNetworkManager->bMovementTimeDiscrepancyResolution)
				{

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

Scope (from outer to inner):

file
function     AGameNetworkManager::AGameNetworkManager

Source code excerpt:

	bMovementTimeDiscrepancyDetection = false;
	bMovementTimeDiscrepancyResolution = false;
	MovementTimeDiscrepancyMaxTimeMargin = 0.25f;
	MovementTimeDiscrepancyMinTimeMargin = -0.25f;
	MovementTimeDiscrepancyResolutionRate = 1.0f;
	MovementTimeDiscrepancyDriftAllowance = 0.0f;
	bMovementTimeDiscrepancyForceCorrectionsDuringResolution = false;
	bUseDistanceBasedRelevancy = true;
}