Caching Simulation Graph Values

When you create a simulation graph, you must use nodes from the Caching category to cache the desired values.

The most basic form of caching involves a CreateCache node to create the cache that holds the values and a CachedValue node to return the values, plus integer constants to control the depth values.

The initFunc of the CreateCache node is the function that sets the initial state of the cache. For example, for a deformation modifier, this would typically be simply the mesh's vertex positions (from the MeshVertices node).

The updateFunc is the function you want to apply iteratively every frame to update values.

The total depth of the cache should be at least 2, to make room for the previous values (level = 1) and the current values (level = 0). A total depth of 1 would mean that the cache initializes instead of updating every time it evaluates. You can use a greater depth if desired, for example, for position trails and other effects.

In some situations, it may also be necessary to cache the evaluation time to prevent issues during playback. For example, you can use a Time implicit parameter, compare it to the cached value, and use the result to control how the simulation updates. The example below shows a simple case that updates the simulation and the time caches only when the current time is different from the cached time.