np2.ReplicationCache.LingerForNSeconds
np2.ReplicationCache.LingerForNSeconds
#Overview
name: np2.ReplicationCache.LingerForNSeconds
This variable is created as a Console Variable (cvar).
- type:
Var
- help:
How long to keep data in the replication cache without the actor accessing it, after this we stop caching the actors state until it tries to access it again.
It is referenced in 4
C++ source files.
#Summary
#Usage in the C++ source code
The purpose of np2.ReplicationCache.LingerForNSeconds
is to control how long data is kept in the replication cache for physics simulation in Unreal Engine 5. This setting is specifically related to the physics replication system.
This setting variable is primarily used in the Chaos physics engine, which is part of Unreal Engine’s physics subsystem. It’s referenced in the FPhysScene_Chaos
class, which is part of the Engine module.
The value of this variable is set through a console variable (CVar) system. It’s initialized with a default value of 3.0 seconds and can be modified at runtime using the console command system.
The associated variable GReplicationCacheLingerForNSeconds
directly interacts with np2.ReplicationCache.LingerForNSeconds
. They share the same value, with GReplicationCacheLingerForNSeconds
being the C++ variable that stores the actual value used in the code.
Developers should be aware that this variable affects the performance and memory usage of the physics replication system. A longer linger time means that physics states for objects will be kept in memory for a longer period, potentially increasing memory usage but reducing the need for recalculation. Conversely, a shorter time will save memory but might increase CPU usage if objects frequently need to re-enter the cache.
Best practices when using this variable include:
- Adjust the value based on the specific needs of your game. Games with many physics objects might benefit from a shorter linger time to save memory.
- Monitor performance metrics when adjusting this value to find the optimal balance between memory usage and CPU performance.
- Consider the network conditions of your target audience. Games with higher latency might benefit from a longer linger time.
Regarding the associated variable GReplicationCacheLingerForNSeconds
:
The purpose of GReplicationCacheLingerForNSeconds
is to store the actual value used in the C++ code for the replication cache linger time.
It’s used directly in the Chaos physics engine code, specifically in the FPhysScene_Chaos::PopulateReplicationCache
function.
The value of this variable is set by the CVar system when np2.ReplicationCache.LingerForNSeconds
is modified.
This variable directly interacts with the physics replication system, determining how long physics states are kept in the replication cache.
Developers should be aware that modifying this variable directly in C++ code is not recommended. Instead, they should use the CVar system to modify np2.ReplicationCache.LingerForNSeconds
.
Best practices for this variable are the same as for np2.ReplicationCache.LingerForNSeconds
, as they are effectively the same setting, just exposed in different ways (CVar vs. C++ variable).
#References in C++ code
#Callsites
This variable is referenced in the following C++ source code:
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/PhysicsEngine/Experimental/PhysScene_Chaos.cpp:60
Scope: file
Source code excerpt:
float GReplicationCacheLingerForNSeconds = 3.f;
FAutoConsoleVariableRef CVar_ReplicationCacheLingerForNSeconds(TEXT("np2.ReplicationCache.LingerForNSeconds"), GReplicationCacheLingerForNSeconds, TEXT("How long to keep data in the replication cache without the actor accessing it, after this we stop caching the actors state until it tries to access it again."));
bool bGClusterUnionSyncBodiesMoveNewComponents = true;
FAutoConsoleVariableRef CVar_GClusterUnionSyncBodiesCheckDirtyFlag(TEXT("p.ClusterUnion.SyncBodiesMoveNewComponents"), bGClusterUnionSyncBodiesMoveNewComponents, TEXT("Enable a fix to ensure new components in a cluster union are moved once on add (even if the cluster is not moving)."));
DECLARE_CYCLE_STAT(TEXT("Update Kinematics On Deferred SkelMeshes"), STAT_UpdateKinematicsOnDeferredSkelMeshesChaos, STATGROUP_Physics);
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Public/Physics/Experimental/PhysScene_Chaos.h:252
Scope: file
Source code excerpt:
ENGINE_API const FRigidBodyState* GetStateFromReplicationCache(UPrimitiveComponent* RootComponent, int& ServerFrame);
/** Register a component for physics replication state caching, the component will deregister automatically if cache is not accessed within timelimit set by CVar: np2.ReplicationCache.LingerForNSeconds */
ENGINE_API void RegisterForReplicationCache(UPrimitiveComponent* RootComponent);
/** Populate the replication cache from the list of registered components */
ENGINE_API void PopulateReplicationCache(const int32 PhysicsStep);
struct FReplicationCacheData
#Associated Variable and Callsites
This variable is associated with another variable named GReplicationCacheLingerForNSeconds
. They share the same value. See the following C++ source code.
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/PhysicsEngine/Experimental/PhysScene_Chaos.cpp:59
Scope: file
Source code excerpt:
FAutoConsoleVariableRef CVar_KinematicDeferralLogInvalidBodies(TEXT("p.KinematicDeferralLogInvalidBodies"), GKinematicDeferralLogInvalidBodies, TEXT("If true and p.KinematicDeferralCheckValidBodies is true, log when an invalid body is found on kinematic update."));
float GReplicationCacheLingerForNSeconds = 3.f;
FAutoConsoleVariableRef CVar_ReplicationCacheLingerForNSeconds(TEXT("np2.ReplicationCache.LingerForNSeconds"), GReplicationCacheLingerForNSeconds, TEXT("How long to keep data in the replication cache without the actor accessing it, after this we stop caching the actors state until it tries to access it again."));
bool bGClusterUnionSyncBodiesMoveNewComponents = true;
FAutoConsoleVariableRef CVar_GClusterUnionSyncBodiesCheckDirtyFlag(TEXT("p.ClusterUnion.SyncBodiesMoveNewComponents"), bGClusterUnionSyncBodiesMoveNewComponents, TEXT("Enable a fix to ensure new components in a cluster union are moved once on add (even if the cluster is not moving)."));
DECLARE_CYCLE_STAT(TEXT("Update Kinematics On Deferred SkelMeshes"), STAT_UpdateKinematicsOnDeferredSkelMeshesChaos, STATGROUP_Physics);
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/PhysicsEngine/Experimental/PhysScene_Chaos.cpp:1363
Scope (from outer to inner):
file
function void FPhysScene_Chaos::PopulateReplicationCache
lambda-function
Source code excerpt:
// If the component reference has lingered in the replication cache for too long without being accessed, remove it and stop caching data.
const Chaos::FReal CacheLingerTime = GetSolver()->GetSolverTime() - ReplicationData.GetAccessTime();
if (CacheLingerTime > GReplicationCacheLingerForNSeconds)
{
StateWasCached = false;
}
else
{
FRigidBodyState& ReplicationState = ReplicationData.GetState();