# Delay Buffer

{% hint style="success" %}
verified: 2025-12-04 version: v39
{% endhint %}

The `M2_DelayBufferComponent` is a helper component that can be used to efficiently sync a data stream to a timestamp, for example to synchronise live streamed lighting data with a separate local timestamp.

The input data is a series of structs (all of the same type) with an associated timestamp. These are added to the delay buffer as they arrive. Then later the data is queried by requesting a timestamp from the buffer and it will return the data from that timestamp, optionally interpolating.

## Usage

Add a `M2_DelayBufferComponent` to your actor, and call `AddItem` with the data and associated timestamp for each new entry. It will return the number of entries currently in the buffer:

<figure><img src="https://1456550285-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoWTlPaoHd1McSakqMigu%2Fuploads%2Fgit-blob-3ae8360a29aa952c5084992fba9c3eca840bd068%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

Call `GetItem` to retrieve the data at a specific timestamp:

<figure><img src="https://1456550285-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoWTlPaoHd1McSakqMigu%2Fuploads%2Fgit-blob-6a7b9db61729772904920de803ba9418d5df0404%2Fimage%20(74).png?alt=media" alt=""><figcaption></figcaption></figure>

The timestamp will be clamped between the timestamps of the first and last entries in the buffer. If `Interpolate` is true then any numeric struct members will be interpolated in the retrieve data (strings etc will just return the value that was last set up until that timestamp). Use `RemoveOlderItems` to manage the size of the buffer, by automatically removing any items that will no longer be used, assuming that the requested timestamp increases monotonically.

There is no enforcement on the nodes that the same struct type is used for every Add and Get call. It is the user's responsibility to use the same type for every call on a given component. If the wrong type is used, an error will be logged and execution will abort.

There are also functions to empty the buffer, and to retrieve a list of all timestamps already in the buffer.

<figure><img src="https://1456550285-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoWTlPaoHd1McSakqMigu%2Fuploads%2Fgit-blob-c56f44cbc2a9cea0c6588d1fbb6de94d955064ca%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>
