---
title: "Play a simulation replay backward"
url: https://recursiveai.org/onescope/cookbook/play-simulation-replay-in-reverse/
description: "Play a OneScope simulation replay backward at a negative step rate, then pause at the current tick without moving the cursor."
version: "1.0.0"
---

# Play a simulation replay backward

**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.Tool) · [GitHub](https://github.com/recursive-ai-oss/onescope-csharp) · [Docs](https://recursiveai.org/onescope/docs/) · [Download example (.zip)](https://recursiveai.org/onescope/cookbook/play-simulation-replay-in-reverse/play-simulation-replay-in-reverse.zip)

Use `run.oppr` from the zip. Headless mode needs a [graphics renderer](https://recursiveai.org/onescope/docs/shell/#pictures).

```shell
dotnet tool install -g RecursiveAI.OneScope.Tool
```

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

```shell
onescope open run.oppr --headless \
  --run 'seek {"step":20}' \
  --run 'play {"speed":-60,"frames":5}' \
  --run 'play {"speed":0}'
```

[The example](https://recursiveai.org/onescope/cookbook/play-simulation-replay-in-reverse/play-simulation-replay-in-reverse.zip) is the full program below: unzip it and `dotnet run`.

The zip contains `run.oppr` and a C# program that runs the same operations, so you can use either the command above or `dotnet run`.

The playback result reports `"step":15`. The pause result keeps step 15 and reports `"playing":false`.

## The full program

The download uses OneScope.Tool 1.0.0 to open a 120-step OnePhysics replay. The headless commands rewind for five presentation frames (counted at 60 per second), then pause; the program prints the cursor after each operation.

```csharp
using System.Diagnostics;
using System.Text.Json;

string toolDir = Path.GetFullPath("obj/onescope-tool");
string tool = Path.Combine(toolDir,
    OperatingSystem.IsWindows() ? "onescope.exe" : "onescope");
if (!File.Exists(tool))
    Run("dotnet", "tool", "install", "RecursiveAI.OneScope.Tool",
        "--version", "1.0.0", "--tool-path", toolDir);

var results = Open(
    """seek {"step":20}""",
    """play {"speed":-60,"frames":5}""",
    """play {"speed":0}""");

foreach (var state in results.TakeLast(2))
{
    string label = state.GetProperty("playing").GetBoolean()
        ? "Playing backward" : "Paused";
    Console.WriteLine($"{label}: step {state.GetProperty("step")}");
}

JsonElement[] Open(params string[] operations)
{
    var arguments = new List<string>
    {
        "open", "run.oppr", "--headless", "--size", "640x480"
    };
    foreach (string operation in operations)
        arguments.AddRange(["--run", operation]);
    return Run(tool, arguments.ToArray())
        .Split('\n', StringSplitOptions.RemoveEmptyEntries)
        .Select(line => JsonDocument.Parse(line).RootElement.Clone())
        .ToArray();
}

static string Run(string command, params string[] arguments)
{
    var start = new ProcessStartInfo(command)
    {
        RedirectStandardOutput = true,
        RedirectStandardError = true
    };
    foreach (string argument in arguments)
        start.ArgumentList.Add(argument);
    using var process = Process.Start(start)!;
    var output = process.StandardOutput.ReadToEndAsync();
    var errors = process.StandardError.ReadToEndAsync();
    process.WaitForExit();
    if (process.ExitCode != 0)
        throw new InvalidOperationException(output.Result + errors.Result);
    return output.Result;
}
```

```text
Playing backward: step 15
Paused: step 15
```

If reverse playback reaches the start with looping off (the default), playback stops there. Seek to a later step first if there’s nothing to rewind.

## Variations

**Watch the replay run backward in a window.** In a terminal, open a window with a control socket. Leave it running:

```shell
onescope open run.oppr --live "$PWD/replay.sock" \
  --run 'seek {"step":100}'
```

In another terminal in the same directory, start reverse playback. Run the second command when you reach the moment you want to inspect:

```shell
onescope play '{"speed":-30}' \
  --socket "$PWD/replay.sock"
onescope play '{"speed":0}' \
  --socket "$PWD/replay.sock"
```

The pause response gives the step where you stopped. Close the replay window when you’re done.

**Go back exactly one simulation tick.** Replace both `play` lines in the headless command with this line; it lands on step 19 without starting playback:

```shell
  --run 'step {"delta":-1}'
```

## Related recipes

- [Seek a simulation replay to a specific tick](https://recursiveai.org/onescope/cookbook/seek-simulation-replay-to-step/)
- [Zoom a replay timeline around a tick](https://recursiveai.org/onescope/cookbook/zoom-replay-timeline-around-a-tick/)

---

## The short answer

Set `play` to a negative `speed` to move backward through the recording, then set `speed` to zero to pause without changing the current step. An open desktop window advances playback as it presents frames. For a headless command, supply `frames` to advance a fixed number of presentation frames before reading the result.

## How do I rewind a replay without restarting it?

Seek to a step after the event you want to review, then start playing at a negative speed. Speed is in simulation steps per presentation second. OneScope’s playback calculation counts 60 presentation frames per second, so at `-60` five frames rewind five steps, as long as the cursor stays away from the start. `moved` is the number of steps moved, not a signed delta; the falling `step` value shows the direction. No simulation state is changed by choosing a playback rate: it only decides which recorded step is shown next.

A window keeps presenting after `play` returns, so for continuous review you don’t need `frames`. If you omit `frames` in a headless run, `play` can report `playing:true` without moving the cursor. Set `frames` there to make the command do the movement immediately. The example starts at step 20 and ends at 15 every run, unlike pausing a window by hand.

## Can I pause a replay and go back one frame?

Pause with `speed:0` before stepping so the window doesn’t continue to advance. If by “frame” you mean one simulation tick, use `step` with `delta:-1`. It’s independent of the playback speed, and clamps at the beginning of the recording. If you know the exact tick you want to inspect, use `seek` instead; the result’s hash identifies the state at that tick, regardless of how you reached it.
