p.Cloth.MaxVelocityScale
p.Cloth.MaxVelocityScale
#Overview
name: p.Cloth.MaxVelocityScale
This variable is created as a Console Variable (cvar).
- type:
Var
- help:
The maximum amount of the component induced velocity allowed on all cloths.\nUse 1.0 for fully induced velocity(default), or use 0.0 for no induced velocity, and any other values in between for a reduced induced velocity.\nWhen set to 0.0, it also provides a way to force the clothing to simulate in local space.\n default: 1.0
It is referenced in 3
C++ source files.
#Summary
#Usage in the C++ source code
The purpose of p.Cloth.MaxVelocityScale is to control the maximum amount of component-induced velocity allowed on all cloth simulations in Unreal Engine 5. This setting is part of the cloth simulation system and affects how cloth objects respond to movement and interactions within the game world.
This setting variable is primarily used by the Clothing System Runtime Common module, which is responsible for handling cloth simulations in Unreal Engine 5. The variable is defined in the ClothingSimulation.cpp file, indicating its close relationship with the core cloth simulation functionality.
The value of this variable is set through a console variable, which allows for runtime modification. It is initialized with a default value of 1.0, but can be changed during gameplay or development.
The p.Cloth.MaxVelocityScale variable interacts directly with its associated variable GClothMaxVelocityScale. They share the same value, and GClothMaxVelocityScale is used in the actual code implementation to apply the velocity scaling.
Developers must be aware of several important aspects when using this variable:
- The value range is between 0.0 and 1.0, where 1.0 allows full induced velocity, and 0.0 completely disables induced velocity.
- Setting the value to 0.0 forces the clothing to simulate in local space, which can be useful for certain effects or optimizations.
- This setting affects all cloth simulations globally, so changes will impact every cloth object in the game.
Best practices for using this variable include:
- Use the default value of 1.0 unless there’s a specific need to reduce cloth responsiveness to component movement.
- Adjust the value carefully, testing different settings to find the right balance between performance and visual quality.
- Consider exposing this setting in the game’s options menu to allow players to adjust cloth performance if needed.
- Use in conjunction with the per-component ClothVelocityScale for more granular control over individual cloth objects.
Regarding the associated variable GClothMaxVelocityScale:
The purpose of GClothMaxVelocityScale is to provide a programmatic interface to the p.Cloth.MaxVelocityScale setting. It allows C++ code to access and modify the cloth velocity scaling at runtime.
This variable is used directly in the cloth simulation code, specifically in the FClothingSimulationContextCommon::FillTeleportMode function. It’s retrieved using the GetValueOnGameThread() method, ensuring thread-safe access to the current value.
The value of GClothMaxVelocityScale is set automatically when p.Cloth.MaxVelocityScale is modified, as they are linked through the console variable system.
Developers should be aware that:
- Any changes to GClothMaxVelocityScale will affect all cloth simulations.
- The value is clamped between 0.0 and 1.0 when used in calculations.
- It interacts with the per-component ClothVelocityScale to determine the final velocity scaling for each cloth object.
Best practices for using GClothMaxVelocityScale include:
- Use GetValueOnGameThread() when accessing the value to ensure thread safety.
- Avoid modifying this variable directly; instead, use the console command to change p.Cloth.MaxVelocityScale.
- Consider caching the value if it’s accessed frequently in performance-critical code sections.
#References in C++ code
#Callsites
This variable is referenced in the following C++ source code:
#Loc: <Workspace>/Engine/Source/Runtime/ClothingSystemRuntimeCommon/Private/ClothingSimulation.cpp:21
Scope: file
Source code excerpt:
static TAutoConsoleVariable<float> GClothMaxVelocityScale(
TEXT("p.Cloth.MaxVelocityScale"),
1.f,
TEXT("The maximum amount of the component induced velocity allowed on all cloths.\n")
TEXT("Use 1.0 for fully induced velocity(default), or use 0.0 for no induced velocity, and any other values in between for a reduced induced velocity.\n")
TEXT("When set to 0.0, it also provides a way to force the clothing to simulate in local space.\n")
TEXT(" default: 1.0"));
#Associated Variable and Callsites
This variable is associated with another variable named GClothMaxVelocityScale
. They share the same value. See the following C++ source code.
#Loc: <Workspace>/Engine/Source/Runtime/ClothingSystemRuntimeCommon/Private/ClothingSimulation.cpp:20
Scope: file
Source code excerpt:
TEXT(" default: 1.5"));
static TAutoConsoleVariable<float> GClothMaxVelocityScale(
TEXT("p.Cloth.MaxVelocityScale"),
1.f,
TEXT("The maximum amount of the component induced velocity allowed on all cloths.\n")
TEXT("Use 1.0 for fully induced velocity(default), or use 0.0 for no induced velocity, and any other values in between for a reduced induced velocity.\n")
TEXT("When set to 0.0, it also provides a way to force the clothing to simulate in local space.\n")
TEXT(" default: 1.0"));
#Loc: <Workspace>/Engine/Source/Runtime/ClothingSystemRuntimeCommon/Private/ClothingSimulation.cpp:180
Scope (from outer to inner):
file
function void FClothingSimulationContextCommon::FillTeleportMode
Source code excerpt:
InComponent->ClothTeleportMode;
const float MaxVelocityScale = FMath::Clamp(GClothMaxVelocityScale.GetValueOnGameThread(), 0.f, 1.f);
const float ComponentVelocityScale = InComponent->ClothVelocityScale;
VelocityScale = (TeleportMode == EClothingTeleportMode::None && InDeltaSeconds > 0.f) ?
FMath::Clamp(ComponentVelocityScale, 0.f, MaxVelocityScale) * FMath::Min(InDeltaSeconds, InMaxPhysicsDelta) / InDeltaSeconds : 0.f;
}