Info
Most of this page was written from 5.6 source code.
Source
See GeometryCache and ChaosCaching plugins.
Console Commands
p.Chaos.Cache.UseInterpolationp.Chaos.Cache.CompressTracksAfterRecording
Core
UGeometryCache
A Geometry Cache is a piece/set of geometry that consists of individual Mesh/Transformation samples. In contrast with Static Meshes they can have their vertices animated in certain ways.
UGeometryCacheComponent
Encapsulates a GeometryCache asset instance and implements functionality for rendering/and playback of GeometryCaches
AChaosCacheManager / AChaosCachePlayer
The AChaosCachePlayer is just a AChaosCacheManager with bCanRecord set to false.
UChaosCacheCollection
Contains a list of recorded UChaosCache.
UChaosCache
Contains recorded data and logic for playback/evaluation.
Physics
FComponentCacheAdapter / FGeometryCollectionCacheAdapter
Playback is done with a FComponentCacheAdapter, see derived class such as FGeometryCollectionCacheAdapter.
Rendering
FGeometryCacheSceneProxy
Procedural mesh scene proxy.
Sequencer
UGeometryCacheTrack
Base class for GeometryCache tracks, stores matrix animation data and implements functionality for it.
UGeometryCacheTrackStreamable
Derived GeometryCacheTrack class, used for Transform animation.
UMovieSceneGeometryCacheSection
Movie scene section that control geometry cache playback.
Niagara
FNiagaraRendererGeometryCache
NiagaraRendererGeometryCache renders a geometry cache asset.
UNiagaraGeometryCacheRendererProperties
Editor
UActorFactoryCacheManager
This is used to spawn AChaosCachePlayer actor when a UChaosCacheCollection is dragged in the world from the Content Browser.
See UActorFactoryCacheManager::PostSpawnActor to know how you can spawn a cache player actor yourself and initialize it by a collection.
The function also spawned the primitive component from the cached duplicated template GCC.
FGeometryCacheAssetEditorToolkit
UAssetDefinition_GeometryCache
Deep Dive
Cache Manager
The intended behavior is to add a Cache Manager actor from the Actor -> Chaos -> Create Cache Manager in the editor toolbar with a Geometry Collection Component selected.
For each Primitive Component your actors holds it will check if any FComponentCacheAdapter accepts it (using ::GetPriority and ::SupportsComponentClass). If the component isn’t already observed by the Cache Manager we call AChaosCacheManager::AddNewObservedComponent to add it.
It will then ask you to set a UChaosCacheCollection asset.
Recording
By default if there is a Cache Manager in a world with at least 1 observed component AChaosCacheManager::BeginEvaluate will be called.
If in Record mode, UChaosCacheCollection::FindOrAddCache will be called for each observed component. This will create a new UChaosCache per component if it doesn’t exist.
A OpenRecordCaches entry is added for each cache that is about to be filled.
Then UChaosCache::BeginRecord is called as well as FComponentCacheAdapter::InitializeForRecord.
On the physics thread FPBDRigidsSolver::BufferPhysicsResults will trigger AChaosCacheManager::HandlePostSolve at each solver step. This will call FComponentCacheAdapter::Record_PostSolve on each observed component if allowed. The function writes out recorded frame data to a FPendingFrameWrite.
A bunch of stuff happens in there, transforms of particles and clusters are cached as needed and events are triggered if relevant.
The FGeometryDynamicCollection stored as PhysicsThreadCollection on the physics proxy (FGeometryCollectionPhysicsProxy) is used to gather transforms.
The filled FPendingFrameWrite is then sent to UChaosCache::AddFrame_Concurrent which enqueues this data toa a mpsc queue (PendingWrites).
This queue is read in UChaosCache::FlushPendingFrames (called by UChaosCacheCollection::FlushAllCacheWrites). At each AChaosCacheManager::TickActor (TG_PrePhysics), UChaosCacheCollection::FlushAllCacheWrites is called on the current collection.
This means that the simulation + recording flow is Physics solver runs -> Frame data is written on post solver -> Game Thread consume queue data and save data to the UChaosCache.
TrackToParticle, ParticleTracks, ChannelCurveToParticle, ParticleToChannelCurve, ChannelsTracks are all written in UChaosCache::FlushPendingFrames_MainPass.
Once the PIE/SIE session ends, AChaosCacheManager::EndPlay will call AChaosCacheManager::EndEvaluate which calls UChaosCache::EndRecord for each OpenRecordCaches. Post record optional compression happens there to.
Playback
Like for the recording path, AChaosCacheManager::BeginEvaluate will called which calls UChaosCache::BeginPlayback and FComponentCacheAdapter::InitializeForPlayback.
The latter will:
- Run first
UChaosCache::Evaluate. - Get all initial transforms and update the dynamic collection using
UGeometryCollectionComponent::SetInitialTransformsandUGeometryCollectionComponent::SetInitialClusterBreaks - Set the dynamic state of all particles of the dynamic collection to
Kinematic - Starts the physics sim with
UGeometryCollectionComponent::SetSimulatePhysics
On the physics thread FPBDRigidsSolver::PrepareAdvanceBy will trigger AChaosCacheManager::HandlePreSolve at each solver step. This will call FComponentCacheAdapter::Playback_PreSolve for each observed component.
This will call UChaosCache::Evaluate and trigger the allowed events and collision events, as well as settings the properties to the physics particles FPBDRigidClusteredParticleHandle (SetP, SetQ, …). It also handles clusters.
The transform data is either gathered using the num transforms from FCacheEvaluationContext InContext input struct or using the number of ParticleTracks which gets the transform with UChaosCache::EvaluateSingle → UChaosCache::EvaluateTransform. → FParticleTransformTrack::Evaluate.