Instanced Static Mesh Components

Notes on Instanced Static Mesh Component behaviour, update costs, removal, and batching.

Efficient updates

Batched updates are more efficient than individual updates.

Prefer functions like BatchUpdateInstancesTransforms and BatchUpdateInstancesData over UpdateInstanceTransform.

For the fastest update speed, I found constructing a TArray<FInstancedStaticMeshInstanceData> with ParallelFor and then using BatchUpdateInstancesData worked best.

BatchUpdateInstancesTransforms takes a TArrayView<FTransform> and converts it to an FMatrix internally.

BatchUpdateInstancesData takes a FInstancedStaticMeshInstanceData* and copies the FMatrix elements directly.

For single-threaded updates, I found BatchUpdateInstancesData to be slower overall than BatchUpdateInstancesTransforms, because the cost of constructing the array of 128-byte FInstancedStaticMeshInstanceData was greater than the time saved in BatchUpdateInstancesData. For comparison, FTransform is 96 bytes.

However, with multithreading the story changes. You can build a TArray<T> very quickly using TArray<T>::AddUninitialized(count) and then constructing the elements using multiple threads.

Since the ISMC update functions are not thread-safe, my testing showed that they became the dominant serial cost. FMatrix-based updates were the fastest.

The main cost is the extra 32 bytes needed per element using FMatrix-based instance data instead of FTransform, but this is small in the context I work at.

Articles