p.HackMaxVelocity2
p.HackMaxVelocity2
#Overview
name: p.HackMaxVelocity2
This variable is created as a Console Variable (cvar).
- type:
Var
- help:
Max cap on velocity: cm/s. This is only a temp solution and should not be relied on as a feature. -1.f to disable
It is referenced in 5
C++ source files.
#Summary
#Usage in the C++ source code
The purpose of p.HackMaxVelocity2 is to set a maximum cap on linear velocity for rigid bodies in the Chaos physics system of Unreal Engine 5. It’s a temporary solution for limiting object speeds in the physics simulation.
This setting variable is primarily used in the Chaos physics system, which is part of Unreal Engine’s experimental physics module. Based on the callsites, it’s utilized in the PBDRigidsEvolutionGBF (Position Based Dynamics Rigid Evolution) component of the Chaos system.
The value of this variable is set through a console variable (CVar) system, allowing it to be adjusted at runtime. It’s initialized with a default value of -1.f, which disables the velocity cap.
The p.HackMaxVelocity2 variable interacts closely with its associated variable HackMaxVelocity. They share the same value and are used interchangeably in the code.
Developers must be aware that this is explicitly stated as a temporary solution and should not be relied upon as a permanent feature. The comment in the code emphasizes this point.
Best practices when using this variable include:
- Use it cautiously and only as a temporary measure.
- Be prepared for it to be deprecated or replaced in future engine versions.
- Consider alternative methods for controlling object velocities that are part of the official, supported feature set.
Regarding the associated variable HackMaxVelocity:
The purpose of HackMaxVelocity is the same as p.HackMaxVelocity2 - to cap the maximum linear velocity of rigid bodies in the Chaos physics system.
It’s used in the same Chaos physics subsystem, specifically within the Integrate function of FPBDRigidsEvolutionGBF.
The value is set through the same console variable system as p.HackMaxVelocity2.
HackMaxVelocity interacts with HackMaxAngularVelocity, which serves a similar purpose for angular velocity.
Developers should be aware that this variable is squared in the code (HackMaxLinearSpeedSq) for performance reasons when comparing against squared velocities.
Best practices for HackMaxVelocity mirror those of p.HackMaxVelocity2, emphasizing its temporary nature and the need for caution when relying on it in production code.
#References in C++ code
#Callsites
This variable is referenced in the following C++ source code:
#Loc: <Workspace>/Engine/Source/Runtime/Experimental/Chaos/Private/Chaos/PBDRigidsEvolutionGBF.cpp:47
Scope (from outer to inner):
file
namespace Chaos
namespace CVars
Source code excerpt:
FRealSingle HackMaxVelocity = -1.f;
FAutoConsoleVariableRef CVarHackMaxVelocity(TEXT("p.HackMaxVelocity2"), HackMaxVelocity, TEXT("Max cap on velocity: cm/s. This is only a temp solution and should not be relied on as a feature. -1.f to disable"));
int DisableThreshold = 5;
FAutoConsoleVariableRef CVarDisableThreshold(TEXT("p.DisableThreshold2"), DisableThreshold, TEXT("Disable threshold frames to transition to sleeping"));
int CollisionDisableCulledContacts = 0;
#Associated Variable and Callsites
This variable is associated with another variable named HackMaxVelocity
. They share the same value. See the following C++ source code.
#Loc: <Workspace>/Engine/Source/Runtime/Experimental/Chaos/Private/Chaos/PBDRigidsEvolutionGBF.cpp:46
Scope (from outer to inner):
file
namespace Chaos
namespace CVars
Source code excerpt:
FAutoConsoleVariableRef CVarHackMaxAngularVelocity(TEXT("p.HackMaxAngularVelocity"), HackMaxAngularVelocity, TEXT("Max cap on angular velocity: rad/s. This is only a temp solution and should not be relied on as a feature. -1.f to disable"));
FRealSingle HackMaxVelocity = -1.f;
FAutoConsoleVariableRef CVarHackMaxVelocity(TEXT("p.HackMaxVelocity2"), HackMaxVelocity, TEXT("Max cap on velocity: cm/s. This is only a temp solution and should not be relied on as a feature. -1.f to disable"));
int DisableThreshold = 5;
FAutoConsoleVariableRef CVarDisableThreshold(TEXT("p.DisableThreshold2"), DisableThreshold, TEXT("Disable threshold frames to transition to sleeping"));
int CollisionDisableCulledContacts = 0;
#Loc: <Workspace>/Engine/Source/Runtime/Experimental/Chaos/Private/Chaos/PBDRigidsEvolutionGBF.cpp:752
Scope (from outer to inner):
file
namespace Chaos
function void FPBDRigidsEvolutionGBF::Integrate
Source code excerpt:
const FReal MaxVelocityBoundsExpansionMACD = GetCollisionConstraints().GetDetectorSettings().MaxVelocityBoundsExpansionMACD;
const FReal HackMaxAngularSpeedSq = CVars::HackMaxAngularVelocity * CVars::HackMaxAngularVelocity;
const FReal HackMaxLinearSpeedSq = CVars::HackMaxVelocity * CVars::HackMaxVelocity;
const bool bAllowMACD = CVars::bChaosUseMACD;
const bool bForceMACD = CVars::bChaosForceMACD;
ParticlesView.ParallelFor([&](auto& GeomParticle, int32 Index)
{
//question: can we enforce this at the API layer? Right now islands contain non dynamic which makes this hard
#Loc: <Workspace>/Engine/Source/Runtime/Experimental/Chaos/Private/Chaos/PBDRigidsEvolutionGBF.cpp:817
Scope (from outer to inner):
file
namespace Chaos
function void FPBDRigidsEvolutionGBF::Integrate
lambda-function
Source code excerpt:
}
if (CVars::HackMaxVelocity >= 0.f)
{
LinearSpeedSq = V.SizeSquared();
if (LinearSpeedSq > HackMaxLinearSpeedSq)
{
V = V * (CVars::HackMaxVelocity / FMath::Sqrt(LinearSpeedSq));
}
}
FVec3 PCoM = Particle.XCom();
FRotation3 QCoM = Particle.RCom();
#Loc: <Workspace>/Engine/Source/Runtime/Experimental/Chaos/Public/Chaos/PBDRigidsEvolutionGBF.h:30
Scope (from outer to inner):
file
namespace Chaos
namespace CVars
Source code excerpt:
{
CHAOS_API extern FRealSingle HackMaxAngularVelocity;
CHAOS_API extern FRealSingle HackMaxVelocity;
CHAOS_API extern FRealSingle SmoothedPositionLerpRate;
CHAOS_API extern bool bChaosCollisionCCDUseTightBoundingBox;
CHAOS_API extern int32 ChaosCollisionCCDConstraintMaxProcessCount;
CHAOS_API extern int32 ChaosSolverDrawCCDThresholds;
}