UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
Chaos::Private::FCollisionConstraintAllocator Class Reference

An allocator and container of collision constraints that supports reuse of constraints from the previous tick. More...

#include <CollisionConstraintAllocator.h>

Public Member Functions

 UE_NONCOPYABLE (FCollisionConstraintAllocator)
 
 FCollisionConstraintAllocator (const int32 InNumCollisionsPerBlock=1000)
 
 ~FCollisionConstraintAllocator ()
 
void SetCollisionContainer (FPBDCollisionConstraints *InCollisionContainer)
 
void SetMaxContexts (const int32 MaxContexts)
 
FCollisionContextAllocatorGetContextAllocator (const int32 Index)
 
TArrayView< FPBDCollisionConstraint *const > GetConstraints () const
 The set of collision constraints for the current tick (created or reinstated)
 
TArrayView< FPBDCollisionConstraint *const > GetCCDConstraints () const
 The set of sweep collision constraints for the current tick (created or reinstated)
 
TArrayView< const FPBDCollisionConstraint *const > GetConstConstraints () const
 The set of collision constraints for the current tick (created or reinstated)
 
int32 GetCurrentEpoch () const
 
bool IsConstraintExpired (const FPBDCollisionConstraint &Constraint)
 
void Reset ()
 Destroy all constraints.
 
void BeginFrame ()
 Called at the start of the frame to clear the frame's active collision list.
 
void BeginDetectCollisions ()
 Called at the start of the tick to prepare for collision detection. Resets the list of active contacts.
 
CHAOS_API void EndDetectCollisions ()
 Called after collision detection to clean up Prunes unused contacts.
 
void PruneExpiredItems ()
 Called each tick after the graph is updated to remove unused collisions.
 
CHAOS_API void ProcessNewMidPhases ()
 
void ProcessInjectedConstraints ()
 If we add new constraints after collision detection, do what needs to be done to add them to the system.
 
void AddActiveConstraint (FPBDCollisionConstraint *Constraint)
 
void AddResimConstraints (const TArray< FPBDCollisionConstraint > &InConstraints, const FCollisionContext Context)
 Add a set of pre-built constraints and build required internal mapping data This is used by the resim cache when restoring constraints after a desync.
 
void SortConstraintsHandles ()
 Sort all the constraints for better solver stability.
 
CHAOS_API void RemoveParticle (FGeometryParticleHandle *Particle)
 Destroy all collision and caches involving the particle Called when a particle is destroyed or disabled (not sleeping).
 
template<typename TLambda >
void VisitConstCollisions (const TLambda &Visitor, const ECollisionVisitorFlags &VisitFlags=ECollisionVisitorFlags::VisitDefault) const
 Iterate over all collisions (read-only), including sleeping ones Visitor signature: ECollisionVisitorResult(const FPBDCollisionConstraint&)
 
template<typename TLambda >
void VisitCollisions (const TLambda &Visitor) const
 Iterate over all collisions (write-enabled), including sleeping ones Visitor signature: ECollisionVisitorResult(FPBDCollisionConstraint&)
 
template<typename TLambda >
void VisitMidPhases (const TLambda &Visitor)
 Iterate over all midphases Visitor signature: ECollisionVisitorResult(FParticlePairMidPhase&)
 
void SetIsDeterministic (const bool bInIsDeterministic)
 

Friends

class FCollisionContextAllocator
 

Detailed Description

An allocator and container of collision constraints that supports reuse of constraints from the previous tick.

All constraint pointers are persistent in memory until Destroy() is called, or until they are pruned.

This allocator maintains the set of all overlapping particle pairs, with each overlapping particle pair managed by a FParticlePairMidPhase object. the MidPhase object is what actually calls the Narrow Phase and maintains the set of collision constraints for all the shape pairs on the particles.

Constraints are allocated during the collision detection phase and retained between ticks. An attempt to create a constraint for the same shape pair as seen on the previous tick will return the existing collision constraint with all of its data intact.

The allocator also keeps a list of Standard and Swept collision constraints that are active for the current tick. This list gets reset and rebuilt every frame during collision detection. It may get added to by the IslandManager if some islands are woken following collision detection.

The allocators Epoch counter is used to determine whether a constraint (or midphase object) generated any contacts for the current frame. When a midphase creates or updates a constraint, it copies the current Epoch counter.

The Midphase list is pruned at the end of each tick so if particles are destroyed or a particle pair is no longer overlapping, the collisions will be destroyed.

When particles are destroyed, we do not immediately destroy the MidPhases (or Collisions) that are associoated with the particle. Instead, we clear the particle pointer from them, but leave their destruction to the pruning process. This avoids the need to parse collision and midphase lists whenever a particle is disabled.

NOTE: To reduce RBAN memory use, we do not create any collision blocks until the first call to CreateCollisionConstraint (see ConstraintPool initialization)

Constructor & Destructor Documentation

◆ FCollisionConstraintAllocator()

Chaos::Private::FCollisionConstraintAllocator::FCollisionConstraintAllocator ( const int32  InNumCollisionsPerBlock = 1000)
inline

◆ ~FCollisionConstraintAllocator()

Chaos::Private::FCollisionConstraintAllocator::~FCollisionConstraintAllocator ( )
inline

Member Function Documentation

◆ AddActiveConstraint()

void Chaos::Private::FCollisionConstraintAllocator::AddActiveConstraint ( FPBDCollisionConstraint Constraint)

This should be called when a sleeping constraint is activated after the narrow phase, typically in the island manager. This is mainly so that any systems asking for a list of active constraints are provided all constraints that may have contributed to the simulation, including those that were added when an island is awoken.

◆ AddResimConstraints()

void Chaos::Private::FCollisionConstraintAllocator::AddResimConstraints ( const TArray< FPBDCollisionConstraint > &  InConstraints,
const FCollisionContext  Context 
)
inline

Add a set of pre-built constraints and build required internal mapping data This is used by the resim cache when restoring constraints after a desync.

◆ BeginDetectCollisions()

void Chaos::Private::FCollisionConstraintAllocator::BeginDetectCollisions ( )
inline

Called at the start of the tick to prepare for collision detection. Resets the list of active contacts.

◆ BeginFrame()

void Chaos::Private::FCollisionConstraintAllocator::BeginFrame ( )
inline

Called at the start of the frame to clear the frame's active collision list.

◆ EndDetectCollisions()

void Chaos::Private::FCollisionConstraintAllocator::EndDetectCollisions ( )

Called after collision detection to clean up Prunes unused contacts.

◆ GetCCDConstraints()

TArrayView< FPBDCollisionConstraint *const > Chaos::Private::FCollisionConstraintAllocator::GetCCDConstraints ( ) const
inline

The set of sweep collision constraints for the current tick (created or reinstated)

Note
Some elements may be null (constraints that have been explicitly deleted)
This is not thread-safe and should not be used during the collision detection phase (i.e., when the list is being built)

◆ GetConstConstraints()

TArrayView< const FPBDCollisionConstraint *const > Chaos::Private::FCollisionConstraintAllocator::GetConstConstraints ( ) const
inline

The set of collision constraints for the current tick (created or reinstated)

Note
Some elements may be null (constraints that have been explicitly deleted)
This is not thread-safe and should not be used during the collision detection phase (i.e., when the list is being built)

◆ GetConstraints()

TArrayView< FPBDCollisionConstraint *const > Chaos::Private::FCollisionConstraintAllocator::GetConstraints ( ) const
inline

The set of collision constraints for the current tick (created or reinstated)

Note
Some elements may be null (constraints that have been deleted)
This is not thread-safe and should not be used during the collision detection phase (i.e., when the list is being built)

◆ GetContextAllocator()

FCollisionContextAllocator * Chaos::Private::FCollisionConstraintAllocator::GetContextAllocator ( const int32  Index)
inline

◆ GetCurrentEpoch()

int32 Chaos::Private::FCollisionConstraintAllocator::GetCurrentEpoch ( ) const
inline

◆ IsConstraintExpired()

bool Chaos::Private::FCollisionConstraintAllocator::IsConstraintExpired ( const FPBDCollisionConstraint Constraint)
inline

Has the constraint expired. An expired constraint is one that was not refreshed this tick.

Note
Sleeping constrainst will report they are expired, but they should not be deleted until awoken. We deliberately don't check the sleeping flag here because it adds a cache miss. This function should be called only when you already know the sleep state (or you must also check IsSleeping())

◆ ProcessInjectedConstraints()

void Chaos::Private::FCollisionConstraintAllocator::ProcessInjectedConstraints ( )
inline

If we add new constraints after collision detection, do what needs to be done to add them to the system.

◆ ProcessNewMidPhases()

void Chaos::Private::FCollisionConstraintAllocator::ProcessNewMidPhases ( )

Collect all the midphases created on the context allocators (probably on multiple threads) and register them

◆ PruneExpiredItems()

void Chaos::Private::FCollisionConstraintAllocator::PruneExpiredItems ( )
inline

Called each tick after the graph is updated to remove unused collisions.

◆ RemoveParticle()

void Chaos::Private::FCollisionConstraintAllocator::RemoveParticle ( FGeometryParticleHandle Particle)

Destroy all collision and caches involving the particle Called when a particle is destroyed or disabled (not sleeping).

◆ Reset()

void Chaos::Private::FCollisionConstraintAllocator::Reset ( )
inline

Destroy all constraints.

◆ SetCollisionContainer()

void Chaos::Private::FCollisionConstraintAllocator::SetCollisionContainer ( FPBDCollisionConstraints InCollisionContainer)
inline

◆ SetIsDeterministic()

void Chaos::Private::FCollisionConstraintAllocator::SetIsDeterministic ( const bool  bInIsDeterministic)
inline

Enable/Disable determinism (extra sorting steps after collision detection)

◆ SetMaxContexts()

void Chaos::Private::FCollisionConstraintAllocator::SetMaxContexts ( const int32  MaxContexts)
inline

◆ SortConstraintsHandles()

void Chaos::Private::FCollisionConstraintAllocator::SortConstraintsHandles ( )
inline

Sort all the constraints for better solver stability.

◆ UE_NONCOPYABLE()

Chaos::Private::FCollisionConstraintAllocator::UE_NONCOPYABLE ( FCollisionConstraintAllocator  )

◆ VisitCollisions()

template<typename TLambda >
void Chaos::Private::FCollisionConstraintAllocator::VisitCollisions ( const TLambda Visitor) const
inline

Iterate over all collisions (write-enabled), including sleeping ones Visitor signature: ECollisionVisitorResult(FPBDCollisionConstraint&)

◆ VisitConstCollisions()

template<typename TLambda >
void Chaos::Private::FCollisionConstraintAllocator::VisitConstCollisions ( const TLambda Visitor,
const ECollisionVisitorFlags VisitFlags = ECollisionVisitorFlags::VisitDefault 
) const
inline

Iterate over all collisions (read-only), including sleeping ones Visitor signature: ECollisionVisitorResult(const FPBDCollisionConstraint&)

◆ VisitMidPhases()

template<typename TLambda >
void Chaos::Private::FCollisionConstraintAllocator::VisitMidPhases ( const TLambda Visitor)
inline

Iterate over all midphases Visitor signature: ECollisionVisitorResult(FParticlePairMidPhase&)

Friends And Related Symbol Documentation

◆ FCollisionContextAllocator


The documentation for this class was generated from the following files: