p.Chaos.ArrayCollection.MaxSlackFraction
p.Chaos.ArrayCollection.MaxSlackFraction
#Overview
name: p.Chaos.ArrayCollection.MaxSlackFraction
This variable is created as a Console Variable (cvar).
- type:
Var
- help:
Shrink particle arrays if the number of slack elements exceeds the number of elements by this fraction
It is referenced in 3
C++ source files.
#Summary
#Usage in the C++ source code
The purpose of p.Chaos.ArrayCollection.MaxSlackFraction is to control the shrinking behavior of particle arrays in the Chaos physics system of Unreal Engine 5. It sets a threshold for when to shrink particle arrays based on the fraction of slack elements.
This setting variable is primarily used in the Chaos physics subsystem, specifically in the PBDRigidsSolver component. It’s part of the experimental Chaos namespace, indicating it’s used in the new physics engine.
The value of this variable is set through a console variable (CVar) system. It’s initialized with a default value of 0.5f and can be changed at runtime using the console command “p.Chaos.ArrayCollection.MaxSlackFraction”.
This variable interacts closely with two other variables:
- bChaosSolverShrinkArrays: A boolean that enables or disables the array shrinking feature.
- ChaosArrayCollectionMinSlack: An integer that sets the minimum number of slack elements to maintain after shrinking.
Developers should be aware that this variable directly impacts memory management and performance in the Chaos physics system. Setting it too low might cause frequent resizing of arrays, while setting it too high might result in unnecessary memory usage.
Best practices when using this variable include:
- Balancing between memory usage and performance. A higher value will use more memory but potentially improve performance by reducing array resizes.
- Testing different values in your specific use case to find the optimal balance.
- Using it in conjunction with the other related variables (bChaosSolverShrinkArrays and ChaosArrayCollectionMinSlack) for fine-tuned control.
The associated variable ChaosArrayCollectionMaxSlackFraction is the actual float variable that stores the value set by the console variable. It’s used directly in the ShrinkArrays function call within the AdvanceOneTimeStepTask::DoWork function. This function is likely part of the main physics update loop.
When working with ChaosArrayCollectionMaxSlackFraction, developers should:
- Understand that it directly affects the behavior of the ShrinkArrays function in the physics solver.
- Be cautious when modifying it at runtime, as it could impact performance and memory usage.
- Consider profiling the application with different values to find the optimal setting for their specific use case.
#References in C++ code
#Callsites
This variable is referenced in the following C++ source code:
#Loc: <Workspace>/Engine/Source/Runtime/Experimental/Chaos/Private/PBDRigidsSolver.cpp:294
Scope (from outer to inner):
file
namespace Chaos
namespace CVars
Source code excerpt:
int32 ChaosArrayCollectionMinSlack = 100;
FAutoConsoleVariableRef CVarChaosSolverShrinkArrays(TEXT("p.Chaos.Solver.ShrinkArrays"), bChaosSolverShrinkArrays, TEXT("Enable/Disable particle array shrinking in the main scene"));
FAutoConsoleVariableRef CVarChaosSolverArrayCollectionMaxSlackFraction(TEXT("p.Chaos.ArrayCollection.MaxSlackFraction"), ChaosArrayCollectionMaxSlackFraction, TEXT("Shrink particle arrays if the number of slack elements exceeds the number of elements by this fraction"));
FAutoConsoleVariableRef CVarChaosSolverArrayCollectionMinSlack(TEXT("p.Chaos.ArrayCollection.MinSlack"), ChaosArrayCollectionMinSlack, TEXT("Do not reduce the size of particle arrays if it would leave less slack than this"));
// Iteration count cvars
// These override the engine config if >= 0
int32 ChaosSolverCollisionPositionFrictionIterations = -1;
#Associated Variable and Callsites
This variable is associated with another variable named ChaosArrayCollectionMaxSlackFraction
. They share the same value. See the following C++ source code.
#Loc: <Workspace>/Engine/Source/Runtime/Experimental/Chaos/Private/PBDRigidsSolver.cpp:291
Scope (from outer to inner):
file
namespace Chaos
namespace CVars
Source code excerpt:
// Shrink particle arrays every frame to recove rmemory when a scene changes significantly
bool bChaosSolverShrinkArrays = false;
float ChaosArrayCollectionMaxSlackFraction = 0.5f;
int32 ChaosArrayCollectionMinSlack = 100;
FAutoConsoleVariableRef CVarChaosSolverShrinkArrays(TEXT("p.Chaos.Solver.ShrinkArrays"), bChaosSolverShrinkArrays, TEXT("Enable/Disable particle array shrinking in the main scene"));
FAutoConsoleVariableRef CVarChaosSolverArrayCollectionMaxSlackFraction(TEXT("p.Chaos.ArrayCollection.MaxSlackFraction"), ChaosArrayCollectionMaxSlackFraction, TEXT("Shrink particle arrays if the number of slack elements exceeds the number of elements by this fraction"));
FAutoConsoleVariableRef CVarChaosSolverArrayCollectionMinSlack(TEXT("p.Chaos.ArrayCollection.MinSlack"), ChaosArrayCollectionMinSlack, TEXT("Do not reduce the size of particle arrays if it would leave less slack than this"));
// Iteration count cvars
// These override the engine config if >= 0
int32 ChaosSolverCollisionPositionFrictionIterations = -1;
#Loc: <Workspace>/Engine/Source/Runtime/Experimental/Chaos/Private/PBDRigidsSolver.cpp:610
Scope (from outer to inner):
file
namespace Chaos
class class AdvanceOneTimeStepTask : public FNonAbandonableTask
function void DoWork
Source code excerpt:
{
QUICK_SCOPE_CYCLE_COUNTER(ShrinkParticleArrays);
MSolver->GetParticles().ShrinkArrays(CVars::ChaosArrayCollectionMaxSlackFraction, CVars::ChaosArrayCollectionMinSlack);
}
if (FRewindData* RewindData = MSolver->GetRewindData())
{
SCOPE_CYCLE_COUNTER(STAT_RewindFinishFrame);
RewindData->FinishFrame();