p.bGeometryCollectionRepUseClusterVelocityMatch

p.bGeometryCollectionRepUseClusterVelocityMatch

#Overview

name: p.bGeometryCollectionRepUseClusterVelocityMatch

This variable is created as a Console Variable (cvar).

It is referenced in 7 C++ source files.

#Summary

#Usage in the C++ source code

The purpose of p.bGeometryCollectionRepUseClusterVelocityMatch is to control the replication behavior of Geometry Collection components in Unreal Engine 5, specifically for cluster state matching using physical velocity.

This setting variable is primarily used in the Geometry Collection Engine module, which is part of Unreal Engine’s experimental features for physics simulation and destruction. It is referenced in the GeometryCollectionComponent.cpp file, indicating its relevance to the Geometry Collection component’s functionality.

The value of this variable is initially set to true in the C++ code, but it can be modified at runtime through the console variable system. It is associated with the C++ boolean variable bGeometryCollectionRepUseClusterVelocityMatch, which directly affects the component’s behavior.

This variable interacts with other replication-related variables and functions within the Geometry Collection component, such as ProcessRepData and UpdateClusterPositionAndVelocitiesFromReplication.

Developers should be aware that this variable affects how cluster states are matched during replication. When set to true, it uses physical velocity for matching cluster states, which can provide more accurate and smooth replication of moving objects. When set to false, the system falls back to periodic hard snapping for synchronization.

Best practices for using this variable include:

  1. Testing the performance and visual results with both true and false settings to determine which works best for your specific use case.
  2. Consider the network conditions and the nature of your geometry collections when deciding whether to use velocity matching or hard snapping.
  3. Use in conjunction with other replication settings like GeometryCollectionHardMissingUpdatesSnapThreshold for fine-tuning the replication behavior.

Regarding the associated variable bGeometryCollectionRepUseClusterVelocityMatch: This is the actual boolean variable that controls the behavior in the C++ code. It is initialized with the same value as the console variable and is used throughout the GeometryCollectionComponent class to determine whether to use velocity matching for cluster states during replication.

The associated variable is set in the ProcessRepData function and used in various other functions like ReplicationShouldHardSnap and UpdateClusterPositionAndVelocitiesFromReplication. It directly influences the replication logic and physics simulation of Geometry Collection components.

Developers should note that changes to the console variable will affect this associated variable, and thus the runtime behavior of Geometry Collection components in networked scenarios.

#References in C++ code

#Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Experimental/GeometryCollectionEngine/Private/GeometryCollection/GeometryCollectionComponent.cpp:2504

Scope: file

Source code excerpt:


bool bGeometryCollectionRepUseClusterVelocityMatch = true;
FAutoConsoleVariableRef CVarGeometryCollectionRepUseClusterVelocityMatch(TEXT("p.bGeometryCollectionRepUseClusterVelocityMatch"), bGeometryCollectionRepUseClusterVelocityMatch,
	TEXT("Use physical velocity to match cluster states"));

int32 GeometryCollectionHardMissingUpdatesSnapThreshold = 20;
FAutoConsoleVariableRef CVarGeometryCollectionHardMissingUpdatesSnapThreshold(TEXT("p.GeometryCollectionHardMissingUpdatesSnapThreshold"), GeometryCollectionHardMissingUpdatesSnapThreshold,
	TEXT("Determines how many missing updates before we trigger a hard snap"));

#Associated Variable and Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Experimental/GeometryCollectionEngine/Private/GeometryCollection/GeometryCollectionComponent.cpp:2503

Scope: file

Source code excerpt:

	TEXT("If true debug draw deltas and corrections for geometry collection replication"));

bool bGeometryCollectionRepUseClusterVelocityMatch = true;
FAutoConsoleVariableRef CVarGeometryCollectionRepUseClusterVelocityMatch(TEXT("p.bGeometryCollectionRepUseClusterVelocityMatch"), bGeometryCollectionRepUseClusterVelocityMatch,
	TEXT("Use physical velocity to match cluster states"));

int32 GeometryCollectionHardMissingUpdatesSnapThreshold = 20;
FAutoConsoleVariableRef CVarGeometryCollectionHardMissingUpdatesSnapThreshold(TEXT("p.GeometryCollectionHardMissingUpdatesSnapThreshold"), GeometryCollectionHardMissingUpdatesSnapThreshold,
	TEXT("Determines how many missing updates before we trigger a hard snap"));

#Loc: <Workspace>/Engine/Source/Runtime/Experimental/GeometryCollectionEngine/Private/GeometryCollection/GeometryCollectionComponent.cpp:2517

Scope (from outer to inner):

file
function     void UGeometryCollectionComponent::ProcessRepData

Source code excerpt:

void UGeometryCollectionComponent::ProcessRepData()
{
	bGeometryCollectionRepUseClusterVelocityMatch = false;
	ProcessRepData(0.f, 0.f);
}

namespace 
{
	bool ReplicationShouldHardSnap(int32 RepDataVersion, int32 VersionProcessed, bool bReplicateMovement, double& LastHardsnapTimeInMs)

#Loc: <Workspace>/Engine/Source/Runtime/Experimental/GeometryCollectionEngine/Private/GeometryCollection/GeometryCollectionComponent.cpp:2541

Scope (from outer to inner):

file
namespace    anonymous
function     bool ReplicationShouldHardSnap

Source code excerpt:

				bHardSnap = (RepDataVersion - VersionProcessed) > GeometryCollectionHardMissingUpdatesSnapThreshold;

				if (!bGeometryCollectionRepUseClusterVelocityMatch)
				{
					// When not doing velocity match for clusters, instead we do periodic hard snapping
					bHardSnap |= (CurrentTimeInMs - LastHardsnapTimeInMs) > GeometryCollectionHardsnapThresholdMs;
				}
			}
			else if (VersionProcessed > RepDataVersion)

#Loc: <Workspace>/Engine/Source/Runtime/Experimental/GeometryCollectionEngine/Private/GeometryCollection/GeometryCollectionComponent.cpp:2609

Scope (from outer to inner):

file
namespace    anonymous
function     bool UpdateClusterPositionAndVelocitiesFromReplication

Source code excerpt:

			bWake = true;
		}
		else if (bGeometryCollectionRepUseClusterVelocityMatch)
		{
			//
			// Match linear velocity
			//
			const FVector RepVel = LinearVelocity;
			const FVector RepExtrapPos = Position + (RepVel * RepExtrapTime);

#Loc: <Workspace>/Engine/Source/Runtime/Experimental/GeometryCollectionEngine/Private/GeometryCollection/GeometryCollectionComponent.cpp:2709

Scope (from outer to inner):

file
namespace    anonymous
function     bool ProcessRepDataCommon

Source code excerpt:

		// Do this one after the debug draw so that we can still easily see the diff
		// between the position and the target position.
		if (VersionProcessed == RepData.Version && !bGeometryCollectionRepUseClusterVelocityMatch)
		{
			return false;
		}

		// Update the anchored state of the root particle
		UpdateRootStateFromReplication(*PhysicsProxy, RepData.bIsRootAnchored);

#Loc: <Workspace>/Engine/Source/Runtime/Experimental/GeometryCollectionEngine/Private/GeometryCollection/GeometryCollectionComponent.cpp:2983

Scope (from outer to inner):

file
function     bool UGeometryCollectionComponent::ProcessRepData
lambda-function

Source code excerpt:

			DrawQueue.DrawDebugBox(RepCluster.Position + Cluster.LocalBounds().Center(), Cluster.LocalBounds().Extents(), RepCluster.Rotation, FColor::Green, false, -1, -1, 1.f);

			if (bGeometryCollectionRepUseClusterVelocityMatch)
			{
				const FVector RepVel = RepCluster.LinearVelocity;
				const FVector RepAngVel = RepCluster.AngularVelocity;
				const FVector RepExtrapPos = RepCluster.Position + (RepVel * RepExtrapTime);
				const Chaos::FRotation3 RepExtrapAng = Chaos::FRotation3::IntegrateRotationWithAngularVelocity(RepCluster.Rotation, RepAngVel, RepExtrapTime);
				DrawQueue.DrawDebugCoordinateSystem(RepExtrapPos, FRotator(RepExtrapAng), 100.f, false, -1, -1, 1.f);