bUseDistanceBasedRelevancy

bUseDistanceBasedRelevancy

#Overview

name: bUseDistanceBasedRelevancy

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 4 C++ source files.

#Summary

#Usage in the C++ source code

The purpose of bUseDistanceBasedRelevancy is to control whether actor network relevancy is determined based on their distance from the client’s viewpoint. This setting is primarily used for network optimization in multiplayer games.

This setting variable is relied upon by the Unreal Engine’s networking system, specifically in the actor replication and pawn replication subsystems. It is used in the Engine module, as evidenced by its presence in GameFramework and ActorReplication components.

The value of this variable is set in the GameNetworkManager constructor (GameNetworkManager.cpp) with a default value of true. It is also marked as a UPROPERTY with the globalconfig specifier, which means it can be configured globally in the project settings.

This variable interacts with the NetCullDistanceSquared property of actors. When bUseDistanceBasedRelevancy is true, actors are only considered network relevant if they are within their NetCullDistanceSquared from the client’s viewpoint.

Developers must be aware that enabling this setting can significantly impact network performance and gameplay experience. It can reduce network traffic by limiting the number of actors that are replicated to clients, but it may also cause issues if important actors suddenly become irrelevant due to distance.

Best practices when using this variable include:

  1. Carefully consider the implications on gameplay before changing the default value.
  2. If enabled, ensure that NetCullDistanceSquared is set appropriately for each actor type to prevent important actors from becoming irrelevant too soon.
  3. Test thoroughly in various network conditions to ensure that the distance-based relevancy doesn’t negatively impact the player experience.
  4. Consider using it in conjunction with other network optimization techniques for best results.
  5. Monitor network performance metrics to validate the effectiveness of this setting in your specific game scenario.

#Setting Variables

#References In INI files

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

Scope (from outer to inner):

file
class        class AGameNetworkManager : public AInfo

Source code excerpt:

	/** If true, actor network relevancy is constrained by whether they are within their NetCullDistanceSquared from the client's view point. */
	UPROPERTY(globalconfig)
	bool	bUseDistanceBasedRelevancy;

protected:

	/** Handle for efficient management of UpdateNetSpeeds timer */
	FTimerHandle TimerHandle_UpdateNetSpeedsTimer;	
};

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/ActorReplication.cpp:410

Scope (from outer to inner):

file
function     bool AActor::IsNetRelevantFor

Source code excerpt:

	}

	return !GetDefault<AGameNetworkManager>()->bUseDistanceBasedRelevancy ||
			IsWithinNetRelevancyDistance(SrcLocation);
}

bool AActor::IsReplayRelevantFor(const AActor* RealViewer, const AActor* ViewTarget, const FVector& SrcLocation, const float CullDistanceOverrideSq) const
{
	return IsNetRelevantFor(RealViewer, ViewTarget, SrcLocation);

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

Scope (from outer to inner):

file
function     AGameNetworkManager::AGameNetworkManager

Source code excerpt:

	MovementTimeDiscrepancyDriftAllowance = 0.0f;
	bMovementTimeDiscrepancyForceCorrectionsDuringResolution = false;
	bUseDistanceBasedRelevancy = true;
}

void AGameNetworkManager::EnableStandbyCheatDetection(bool bIsEnabled)
{
	UNetDriver* Driver = GetWorld()->GetNetDriver();
	if (Driver)

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/Pawn.cpp:1250

Scope (from outer to inner):

file
function     bool APawn::IsNetRelevantFor

Source code excerpt:

	}

	return !GetDefault<AGameNetworkManager>()->bUseDistanceBasedRelevancy ||
			IsWithinNetRelevancyDistance(SrcLocation);
}

void APawn::GetLifetimeReplicatedProps( TArray< FLifetimeProperty > & OutLifetimeProps ) const
{
	Super::GetLifetimeReplicatedProps( OutLifetimeProps );