---
title: "pixelCast(origin:direction:length:)"
framework: realitykit
role: symbol
role_heading: Instance Method
path: "realitykit/scene/pixelcast(origin:direction:length:)"
---

# pixelCast(origin:direction:length:)

Performs a ray cast against all the geometry in the scene for a ray of a given origin, direction, and length.

## Declaration

```swift
@MainActor @preconcurrency func pixelCast(origin: SIMD3<Float>, direction: SIMD3<Float>, length: Float = 100) async throws -> PixelCastHit?
```

## Parameters

- `origin`: The origin of the ray relative to the scene.
- `direction`: The direction of the ray relative to the scene.
- `length`: The length of the ray relative to the scene.

## Return Value

Return Value A PixelCastHit. The hit indicates where the ray, starting at a given point and traveling in a given direction, hit a particular entity in the scene.

## Discussion

Discussion The method ignores entities that lack a ModelComponent with a valid mesh.

## See Also

### Detecting intersections

- [raycast(origin:direction:length:query:mask:relativeTo:)](realitykit/scene/raycast(origin:direction:length:query:mask:relativeto:).md)
- [raycast(from:to:query:mask:relativeTo:)](realitykit/scene/raycast(from:to:query:mask:relativeto:).md)
- [convexCast(convexShape:fromPosition:fromOrientation:toPosition:toOrientation:query:mask:relativeTo:)](realitykit/scene/convexcast(convexshape:fromposition:fromorientation:toposition:toorientation:query:mask:relativeto:).md)
- [pixelCast(from:to:)](realitykit/scene/pixelcast(from:to:).md)
