---
title: "Seek a simulation replay to a specific tick in C#"
url: https://recursiveai.org/onescope/cookbook/seek-simulation-replay-to-step/
description: "Jump to a tick in a local simulation recording with OneScope’s History.Seek API in C#, then read the world at that tick or rewind to an earlier one."
version: "1.0.0"
---

# Seek a simulation replay to a specific tick in C#

**OneScope** is a free, open-source viewer for simulation recordings, with a desktop window or command-line control, from Recursive AI. MIT or Apache-2.0.

[NuGet](https://www.nuget.org/packages/RecursiveAI.OneScope.Sdk) · [GitHub](https://github.com/recursive-ai-oss/onescope-csharp) · [Docs](https://recursiveai.org/onescope/docs/) · [Download example (.zip)](https://recursiveai.org/onescope/cookbook/seek-simulation-replay-to-step/seek-simulation-replay-to-step.zip)

Use `CounterModule.cs` and `counter.replay` from the zip. A tick is one simulation step.

```shell
dotnet add package RecursiveAI.OneScope.Sdk
```

Requires [.NET 10](https://dotnet.microsoft.com/download/dotnet/10.0) (net10.0); .NET 9 and earlier aren’t supported.

```csharp
var history = CounterModule
    .OpenHistory("counter.replay");
history.Seek(3);
var world = (CounterWorld)history.World;
long tick = history.CurrentStep;
Console.WriteLine($"Tick: {tick}");
Console.WriteLine($"Count: {world.Count}");
```

Unzip [the example](https://recursiveai.org/onescope/cookbook/seek-simulation-replay-to-step/seek-simulation-replay-to-step.zip), then `dotnet run`.

```text
Tick: 3
Count: 6
```

## Program and rewind

A OneScope module reads a recording format and steps its simulation world. If you have your own recording format, see [Writing a module](https://recursiveai.org/onescope/docs/module-authoring/).

The included `counter.replay` uses the sample module’s toy format; `COUNT 4` records four ticks:

```text
COUNT 4
```

`OpenHistory` is a helper in `CounterModule.cs` that reads the file, calls the module’s `Open` method, and creates a `History`. The full program does those steps directly.

The module starts at tick 0 with a count of 0 and adds two per tick. The program seeks to tick 3 and then rewinds to tick 1:

```csharp
using OneScope.Sdk;

const string path = "counter.replay";
var bytes = File.ReadAllBytes(path);
var source = new CounterModule()
    .Open(bytes, path);
var history = new History(source);
history.Seek(3);
var world = (CounterWorld)history.World;
long tick = history.CurrentStep;
Console.WriteLine($"Tick: {tick}");
Console.WriteLine($"Count: {world.Count}");

history.Seek(1);
Console.WriteLine($"Rewound to tick {history.CurrentStep}.");
Console.WriteLine($"Count: {((CounterWorld)history.World).Count}");
```

```text
Tick: 3
Count: 6
Rewound to tick 1.
Count: 2
```

A tick outside the inclusive `StartStep` to `EndStep` range throws `ArgumentOutOfRangeException`.

## Variations

To jump to the final tick without knowing how long the recording is, replace `history.Seek(3)`:

```csharp
history.Seek(history.EndStep);
```

```text
Tick: 4
Count: 8
```

## Related recipes

- [Seek on a custom axis](https://recursiveai.org/onescope/cookbook/seek-replay-on-custom-axis/)
- [Bound replay keyframe memory](https://recursiveai.org/onescope/cookbook/bound-replay-keyframe-memory/)

## The short answer

Use `History.Seek(tick)` with the recorded tick number, then read `History.World`. A seek restores a suitable keyframe (a saved world state) when needed and replays recorded inputs up to the target. The snippet reaches tick 3 with a count of 6; the full example then seeks backward to tick 1 and reads a count of 2.

## What makes a seek in a deterministic simulation land on the exact tick?

The module has to restore the same state its world reached when it first saved the keyframe. Replaying the same inputs from that state must produce the same result as stepping straight through. `Seek` uses the nearest retained keyframe at or before the target, unless it can continue forward from the current world. It does not interpolate between visible frames. This is useful when comparing state at the exact tick a simulation first diverges, regardless of how often a viewer draws the screen.

The argument is an absolute tick, not an offset and not a wall-clock time. Use `StartStep` and `EndStep` for a scrubber’s range. In the sample, four recorded advances take the world from tick 0 to tick 4, so both endpoints are valid. If you have an offset from the start of a recording, add it to `StartStep` before seeking. Read the world state you need before the next seek or step: `History.World` is the current world, not a snapshot you can hold onto as the cursor moves.
