p.Cloth.TeleportDistanceThreshold

p.Cloth.TeleportDistanceThreshold

#Overview

name: p.Cloth.TeleportDistanceThreshold

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

It is referenced in 3 C++ source files.

#Summary

#Usage in the C++ source code

The purpose of p.Cloth.TeleportDistanceThreshold is to set a distance threshold for cloth teleportation in Unreal Engine’s cloth simulation system. It is used to determine when a character’s movement is significant enough to trigger a cloth teleportation event.

This setting variable is primarily used in the cloth simulation system, which is part of Unreal Engine’s physics and animation subsystems. It is specifically referenced in the SkeletalMeshComponentPhysics module.

The value of this variable is set as a console variable with a default value of 300.0 units. It can be modified at runtime through the console or programmatically.

This variable interacts with several other cloth-related variables:

  1. p.Cloth.TeleportOverride: Must be set to true for this threshold to take effect.
  2. p.Cloth.ResetAfterTeleport: Determines if the cloth should reset after teleportation.
  3. p.Cloth.TeleportRotationThreshold: A rotation threshold that works in conjunction with the distance threshold.

Developers must be aware that:

  1. This variable only takes effect when p.Cloth.TeleportOverride is set to true.
  2. The threshold is applied per frame, so it’s sensitive to frame rate and sudden movements.
  3. Zero or negative values will skip the distance check entirely.

Best practices when using this variable include:

  1. Tuning the value based on the scale and movement speed of your characters.
  2. Using it in conjunction with p.Cloth.TeleportRotationThreshold for more precise control.
  3. Testing thoroughly with various movement scenarios to ensure cloth behavior remains realistic.

Regarding the associated variable CVarClothTeleportDistanceThreshold:

The purpose of CVarClothTeleportDistanceThreshold is to provide a programmatic interface to the p.Cloth.TeleportDistanceThreshold console variable. It allows C++ code to read and potentially modify the teleport distance threshold at runtime.

This variable is used in the same subsystem (cloth simulation) and module (SkeletalMeshComponentPhysics) as p.Cloth.TeleportDistanceThreshold.

The value of CVarClothTeleportDistanceThreshold is set when the console variable p.Cloth.TeleportDistanceThreshold is initialized or changed.

It interacts directly with the cloth simulation logic, particularly in the CheckClothTeleport function of the USkeletalMeshComponent class.

Developers should be aware that changes to this variable will immediately affect the cloth simulation behavior, potentially causing visual inconsistencies if changed abruptly.

Best practices for using CVarClothTeleportDistanceThreshold include:

  1. Using it for runtime adjustments of the teleport threshold, such as for different gameplay scenarios or debug purposes.
  2. Ensuring that any modifications are properly synchronized with other cloth-related variables.
  3. Considering performance implications when frequently accessing or modifying this value, as it may be called every frame during cloth simulation.

#References in C++ code

#Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/SkeletalMeshComponentPhysics.cpp:55

Scope: file

Source code excerpt:

static TAutoConsoleVariable<bool> CVarClothTeleportOverride(TEXT("p.Cloth.TeleportOverride"), false, TEXT("Force console variable teleport override values over skeletal mesh properties.\n Default: false."));
static TAutoConsoleVariable<bool> CVarClothResetAfterTeleport(TEXT("p.Cloth.ResetAfterTeleport"), true, TEXT("Require p.Cloth.TeleportOverride. Reset the clothing after moving the clothing position (called teleport).\n Default: true."));
static TAutoConsoleVariable<float> CVarClothTeleportDistanceThreshold(TEXT("p.Cloth.TeleportDistanceThreshold"), 300.f, TEXT("Require p.Cloth.TeleportOverride. Conduct teleportation if the character's movement is greater than this threshold in 1 frame.\n Zero or negative values will skip the check.\n Default: 300."));
static TAutoConsoleVariable<float> CVarClothTeleportRotationThreshold(TEXT("p.Cloth.TeleportRotationThreshold"), 0.f, TEXT("Require p.Cloth.TeleportOverride. Rotation threshold in degrees, ranging from 0 to 180.\n Conduct teleportation if the character's rotation is greater than this threshold in 1 frame.\n Zero or negative values will skip the check.\n Default 0."));

static TAutoConsoleVariable<int32> CVarEnableKinematicDeferralPrePhysicsCondition(TEXT("p.EnableKinematicDeferralPrePhysicsCondition"), 1, TEXT("If is 1, and deferral would've been disallowed due to EUpdateTransformFlags, allow if in PrePhysics tick. If 0, condition is unchanged."));

//This is the total cloth time split up among multiple computation (updating gpu, updating sim, etc...)
DECLARE_CYCLE_STAT(TEXT("Cloth Total"), STAT_ClothTotalTime, STATGROUP_Physics);

#Associated Variable and Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/SkeletalMeshComponentPhysics.cpp:55

Scope: file

Source code excerpt:

static TAutoConsoleVariable<bool> CVarClothTeleportOverride(TEXT("p.Cloth.TeleportOverride"), false, TEXT("Force console variable teleport override values over skeletal mesh properties.\n Default: false."));
static TAutoConsoleVariable<bool> CVarClothResetAfterTeleport(TEXT("p.Cloth.ResetAfterTeleport"), true, TEXT("Require p.Cloth.TeleportOverride. Reset the clothing after moving the clothing position (called teleport).\n Default: true."));
static TAutoConsoleVariable<float> CVarClothTeleportDistanceThreshold(TEXT("p.Cloth.TeleportDistanceThreshold"), 300.f, TEXT("Require p.Cloth.TeleportOverride. Conduct teleportation if the character's movement is greater than this threshold in 1 frame.\n Zero or negative values will skip the check.\n Default: 300."));
static TAutoConsoleVariable<float> CVarClothTeleportRotationThreshold(TEXT("p.Cloth.TeleportRotationThreshold"), 0.f, TEXT("Require p.Cloth.TeleportOverride. Rotation threshold in degrees, ranging from 0 to 180.\n Conduct teleportation if the character's rotation is greater than this threshold in 1 frame.\n Zero or negative values will skip the check.\n Default 0."));

static TAutoConsoleVariable<int32> CVarEnableKinematicDeferralPrePhysicsCondition(TEXT("p.EnableKinematicDeferralPrePhysicsCondition"), 1, TEXT("If is 1, and deferral would've been disallowed due to EUpdateTransformFlags, allow if in PrePhysics tick. If 0, condition is unchanged."));

//This is the total cloth time split up among multiple computation (updating gpu, updating sim, etc...)
DECLARE_CYCLE_STAT(TEXT("Cloth Total"), STAT_ClothTotalTime, STATGROUP_Physics);

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/SkeletalMeshComponentPhysics.cpp:3586

Scope (from outer to inner):

file
function     void USkeletalMeshComponent::CheckClothTeleport

Source code excerpt:

	{
		bResetAfterTeleportOverride = CVarClothResetAfterTeleport.GetValueOnGameThread();
		TeleportDistanceThresholdOverride = CVarClothTeleportDistanceThreshold.GetValueOnGameThread();
		ClothTeleportDistThresholdSquaredOverride = FMath::Square(TeleportDistanceThresholdOverride);
		TeleportRotationThresholdOverride = CVarClothTeleportRotationThreshold.GetValueOnGameThread();
		ClothTeleportCosineThresholdInRadOverride = FMath::Cos(FMath::DegreesToRadians(TeleportRotationThresholdOverride));
	}
	else
	{