ClothSimulationComponent
A component that marks an entity as the simulation root of a localized cloth simulation.
Declaration
struct ClothSimulationComponentOverview
Each entity in a scene belongs to at most one cloth simulation, which is the ancestor closest in the entity hierarchy with a ClothSimulationComponent. Separate simulations do not interact with each other, which can improve power and performance. As an example, if you want two cloth simulations, then you can set up your entity hierarchy as follows.
- scene
- entity1 (ClothSimulationComponent)
- entity2 (ClothBodyComponent)
- entity3 (ClothSimulationComponent)
- entity4 (ClothBodyComponent)
- entity5
- entity6 (ClothColliderComponent)In the above example, entity1 is the root of a cloth simulation and entity2 is part of that simulation. Similarly, entity3 is the root of a different cloth simulation that entity4, entity5, and entity6 are all part of.
The simulation component itself mainly configures the quality, performance, and pace of the simulation. The solver and time step together balance the quality vs. performance of the simulation. You can guide the pace of the simulation by controlling its target clock (targetClock). Meanwhile, you can also follow the pace of the simulation by syncing with its simulation clock (simulationClock).
On thermally constrained devices, sustained cloth simulation work can contribute to system heat, and the device may begin throttling once the thermal state escalates beyond .nominal. To stay responsive to the device’s available thermal headroom, read ProcessInfo.processInfo.thermalState and observe ProcessInfo.thermalStateDidChangeNotification to react when it changes. As the reported state moves from .fair toward .serious and .critical, dial back simulation cost. For example, you can lower maximumStepsPerUpdate, increase meshCollidersUpdateInterval, prefer implicit collider shapes (sphere, box, capsule, etc.) over mesh colliders where possible, or choose a cheaper solver configuration via ClothSimulationComponent.Solver. Reducing the number of active simulations and the particle count of bodies within them is also effective, since power and performance costs scale with both.
The simulation component also stores various parameters that affect the entire simulation, like gravity. Notably, it stores the collection of runtime-modifiable materials that are available to its bodies (ClothBodyComponent) and colliders (ClothColliderComponent). The exact interactions between these materials can be further configured through the simulation’s friction overrides.
Topics
Creating a cloth simulation
Configuring the solver
Applying forces
Assigning materials
Overriding friction
Controlling simulation timing
timeStepmaximumStepsPerUpdateClothSimulationComponent.MaximumStepsPerUpdatespeedLimitClothSimulationComponent.SpeedLimitmeshCollidersUpdateInterval