p.Chaos.Solver.ShrinkArrays
p.Chaos.Solver.ShrinkArrays
#Overview
name: p.Chaos.Solver.ShrinkArrays
This variable is created as a Console Variable (cvar).
- type:
Var
- help:
Enable/Disable particle array shrinking in the main scene
It is referenced in 3
C++ source files.
#Summary
#Usage in the C++ source code
The purpose of p.Chaos.Solver.ShrinkArrays is to control the particle array shrinking functionality in the Chaos physics solver of Unreal Engine 5. This setting is specifically related to memory management in the physics simulation system.
This setting variable is primarily used in the Chaos physics subsystem, which is part of Unreal Engine’s experimental physics simulation module. It’s referenced in the PBDRigidsSolver.cpp file, which is part of the Chaos solver implementation.
The value of this variable is set through a console variable (CVar) system, allowing it to be adjusted at runtime. It’s associated with the boolean variable bChaosSolverShrinkArrays, which directly controls whether the shrinking functionality is enabled or disabled.
Other variables that interact with it include:
- ChaosArrayCollectionMaxSlackFraction
- ChaosArrayCollectionMinSlack
These variables work together to fine-tune the array shrinking behavior.
Developers should be aware that enabling this setting (setting it to true) will cause the solver to attempt to recover memory by shrinking particle arrays every frame when a scene changes significantly. This can help manage memory usage but may have performance implications.
Best practices when using this variable:
- Use it in conjunction with the associated MaxSlackFraction and MinSlack settings to balance memory usage and performance.
- Monitor performance when enabling this feature, as frequent array resizing could impact frame rates.
- Consider enabling it in memory-constrained environments or when dealing with highly dynamic scenes where particle counts fluctuate significantly.
Regarding the associated variable bChaosSolverShrinkArrays: This is a boolean variable that directly controls whether the array shrinking functionality is active. When set to true, it enables the shrinking of particle arrays in the main scene of the Chaos solver. It’s used in the AdvanceOneTimeStepTask to determine whether to call the ShrinkArrays function on the solver’s particles.
Developers should be cautious when modifying this variable, as it can affect both memory usage and performance. It’s best to test thoroughly in various scenarios to ensure it provides the desired balance between memory efficiency and computational overhead for your 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:293
Scope (from outer to inner):
file
namespace Chaos
namespace CVars
Source code excerpt:
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
#Associated Variable and Callsites
This variable is associated with another variable named bChaosSolverShrinkArrays
. They share the same value. See the following C++ source code.
#Loc: <Workspace>/Engine/Source/Runtime/Experimental/Chaos/Private/PBDRigidsSolver.cpp:290
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
#Loc: <Workspace>/Engine/Source/Runtime/Experimental/Chaos/Private/PBDRigidsSolver.cpp:607
Scope (from outer to inner):
file
namespace Chaos
class class AdvanceOneTimeStepTask : public FNonAbandonableTask
function void DoWork
Source code excerpt:
// Recover unused memory from particle arrays, based on the array shrink policy
if (bChaosSolverShrinkArrays)
{
QUICK_SCOPE_CYCLE_COUNTER(ShrinkParticleArrays);
MSolver->GetParticles().ShrinkArrays(CVars::ChaosArrayCollectionMaxSlackFraction, CVars::ChaosArrayCollectionMinSlack);
}
if (FRewindData* RewindData = MSolver->GetRewindData())