In this lesson, you will learn how to bake complex Chaos destruction sequences into Geometry Cache assets to ensure your gameplay remains smooth, predictable, and performant.
Why Cache Destruction?
When you use live physics to shatter objects, the engine must calculate every collision, fragment movement, and constraint interaction in real-time. If you have a massive explosion with hundreds of pieces, this can lead to "physics spikes" that drop your frame rate. By using Caching, you convert those dynamic physics calculations into a pre-recorded animation sequence that plays back without needing the physics engine to simulate the fragments every time.
Utilizing Geometry Cache
To implement this, you use the Chaos Cache Manager. Instead of letting the physics engine calculate the debris on the fly during a chaotic boss fight or a cinematic moment, you record the destruction once.
- Record: Add a
GeometryCachecomponent to your actor. During simulation, use the "Record" functionality in yourGeometryCachesettings to capture the movement and rotation of every fractured piece. - Store: This creates an asset that stores the transform data for every frame of the fracture.
- Play back: In your level, you replace the dynamic
GeometryCollectionwith yourGeometryCache. When the player triggers the event, the engine plays the recorded "movie" of the destruction rather than calculating physics.
Implementation Logic
You can use the GeometryCacheComponent to trigger your destruction at the exact moment a player hits a specific gameplay threshold. Because the movement is now baked data, it will look identical every time it plays:
// Example: Switching from Physics to Cache
void AMyDestructibleActor::TriggerBakedDestruction()
{
// Disable physics simulation to save resources
MyGeometryCollectionComponent->SetSimulatePhysics(false);
// Enable the pre-recorded Geometry Cache
MyGeometryCacheComponent->SetVisibility(true);
MyGeometryCacheComponent->PlayFromStart();
}
This ensures that your large-scale destruction looks cinematic and consistent, regardless of the player's computer performance or complex physics interactions happening elsewhere in the game.
Key Takeaway: Caching transforms dynamic physics simulations into static, high-performance playback sequences, allowing you to trigger complex destruction without risking frame rate drops or inconsistent physical behavior.