---
title: "Find a replay entity at a screen coordinate"
url: https://recursiveai.org/onescope/cookbook/pick-replay-entity-at-screen-point/
description: "Find the simulation entity under a window pixel with OneScope’s pick command. Read its ID and world point, or detect a miss."
version: "1.0.0"
---

# Find a replay entity at a screen coordinate

**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/pick-replay-entity-at-screen-point/pick-replay-entity-at-screen-point.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 \
  --size 640x480 --run 'seek {"step":20}' \
  --run capture_frame \
  --run 'pick {"view":0,"x":233,"y":174}'
```

[The example](https://recursiveai.org/onescope/cookbook/pick-replay-entity-at-screen-point/pick-replay-entity-at-screen-point.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 last JSON result is the hit:

```json
{"view":0,"source":0,"entity":72057598332895233,"point":[0,3.3707314,0]}
```

## The full program

The example installs OneScope.Tool 1.0.0 into its build folder and opens the bundled physics recording, made with [OnePhysics](https://recursiveai.org/onephysics/), at step 20. It lays out the whole shell with `capture_frame`, then checks a pixel on the ball and one in empty space. Without a capture or a rendered window frame to lay out the view, `pick` returns `rejected`.

```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}""",
    "capture_frame",
    """pick {"x":233,"y":174,"view":0}""",
    """pick {"x":233,"y":205,"view":0}""");

foreach (var pick in results.TakeLast(2))
{
    var entity = pick.GetProperty("entity");
    Console.WriteLine(entity.ValueKind == JsonValueKind.Null
        ? "Miss"
        : $"Hit: {entity.GetUInt64()}");
    Console.WriteLine($"World point: {pick.GetProperty("point")}");
}

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
Hit: 72057598332895233
World point: [0,3.3707314,0]
Miss
World point: [0,-5.097561,0]
```

## Variations

**Let OneScope find the view.** Use the same command but replace its last line with this one. OneScope finds the scene view under the window pixel; outside all views it returns `not_found`.

```shell
  --run 'pick {"x":233,"y":174}'
```

## Related recipes

- [Get the screen coordinates of a replay entity](https://recursiveai.org/onescope/cookbook/project-replay-entity-to-screen/)
- [Find entity IDs and inspect replay properties](https://recursiveai.org/onescope/cookbook/inspect-replay-entity-properties/)

---

## The short answer

Call `pick` with `x` and `y` in window pixels and, optionally, the scene view number. The result names the view and its replay source, reports the entity ID or `null`, and includes a world-space `point`. Check `entity`, not `point`, to decide whether there was a hit.

## How do I find the object under a mouse click?

Pass the click’s coordinates relative to the whole OneScope window, not relative to the scene panel or your desktop. If you’re picking from a screenshot, use a full-shell capture at the same layout and size, not a crop or a view-only export. The sample fixes the shell at 640 × 480 and seeks before laying out the views, so `(233, 174)` is over the ball in view 0 at step 20. At a different step or after resizing or panning, that same pixel may hit something else.

Picking tests what the replay module draws with the view’s enabled overlays. An entity in the inspector isn’t necessarily drawn. In a 2D view, OneScope maps the pixel onto the world plane at `z = 0`; in a 3D view, it casts a ray from the camera. A 2D hit point is the mapped pointer position, not the center of the object. Use [`project`](https://recursiveai.org/onescope/cookbook/project-replay-entity-to-screen/) for the opposite task: getting an annotation position from an ID you already know.

## How do I detect a click in empty space?

Empty space inside a view is a successful `pick` with `"entity":null`. In the example, the second point still has a world position because the pixel maps onto the 2D plane. A click outside all scene views is different: if you let OneScope choose the view, it returns `not_found` because there’s no view to test. Keep those cases separate if a click on empty scene space clears a selection but a click on a toolbar shouldn’t.

The entity ID is an unsigned 64-bit integer. Read it as an integer rather than a floating-point value: the sample’s ID is already too large to round-trip through a JavaScript `Number`. When sending an ID to another shell operation, [the shell accepts the digits as a JSON string](https://recursiveai.org/onescope/docs/shell/#operations).
