Skip to content

URayCastSensor

Raycast sensor that collects observations by casting rays into the environment.

This sensor fires multiple rays in a cone or full circle pattern, detecting objects and measuring distances. For each ray, it reports whether an object was hit, the hit distance, and which tracked tags (if any) the hit object has. Useful for navigation and obstacle detection.

class URayCastSensor : public USceneComponent, public IScholaSensor

Methods

GetObservationSpace_Implementation

virtual void GetObservationSpace_Implementation(
FInstancedStruct &OutObservationSpace) const override

Get the observation space for this sensor.

Parameters

  • OutObservationSpace (FInstancedStruct)

GenerateRayEndpoints

void GenerateRayEndpoints(int32 InNumRays, float InRayDegrees,
FVector InBaseEnd, FVector InStart,
FTransform InBaseTransform, FVector InEndOffset,
TArray<FVector> &OutRayEndpoints)

Generate the endpoints of the rays to be cast.

Parameters

  • InNumRays (int32)

  • InRayDegrees (float)

  • InBaseEnd (FVector)

  • InStart (FVector)

  • InBaseTransform (FTransform)

  • InEndOffset (FVector)

  • OutRayEndpoints (TArray<FVector>)


AppendEmptyTags

void AppendEmptyTags(FBoxPoint &OutObservations)

Add empty tags to the observation for rays that miss.

Parameters

  • OutObservations (FBoxPoint)

CollectObservations_Implementation

virtual void
CollectObservations_Implementation(FInstancedStruct &OutObservations) override

Collect observations about the environment state by casting rays.

Parameters

  • OutObservations (FInstancedStruct)

GenerateId

FString GenerateId() const

Generate a unique ID string for this sensor.


HandleRayHit

static void HandleRayHit(const UWorld *World, const TArray<FName> &TrackedTags,
const FHitResult &InHitResult,
TArrayView<float> &OutObservations,
const FVector &InStart)

Handle a successful ray trace and append observation data.

Parameters

  • World (const UWorld)

  • TrackedTags (const TArray<FName>)

  • InHitResult (const FHitResult)

  • OutObservations (TArrayView<float>)

  • InStart (const FVector)

Attributes

RayLength

float RayLength = 4096.f

Sphere radius for debug visualization at hit points.


CollisionChannel

TEnumAsByte<ECollisionChannel> CollisionChannel

The collision channel to use for the raycast.


bDrawDebugLines

bool bDrawDebugLines = false

Does this sensor draw debug lines/spheres during runtime.


bTraceComplex

bool bTraceComplex = false

Should the sensor trace against complex collision.


NumRays

int32 NumRays = 2

The number of rays to fire.


RayDegrees

float RayDegrees = 90.0f

The angle between the first and last ray.


TrackedTags

TArray<FName> TrackedTags

Actor tags that are checked on raycast collision.


RayEndOffset

FVector RayEndOffset

A position adjustment that is applied to end points of the generated ray trajectories.


DebugHitColor

FColor DebugHitColor = FColor::Green

Debug color for ray hit (when ray intersects an object).


DebugMissColor

FColor DebugMissColor = FColor::Red

Debug color for ray miss (when ray hits nothing).


bEnableParallelTracing

bool bEnableParallelTracing = false

Should the sensor run raytraces in parallel.


MinParallelBatchSize

int32 MinParallelBatchSize = 1

The minimum number of rays to process in each parallel batch.

Source: Source/ScholaInteractors/Public/Sensors/RayCastSensor.h