Skip to content

Class URayCastSensor

Class URayCastSensor

  • Defined in File RayCastSensor.h

Inheritance Relationships

Base Types

class URayCastSensor : public USceneComponent, public IScholaSensor

Source: Source/Schola/Interactors/Public/Sensors/RayCastSensor.h

Dependencies: FBoxPoint

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.


Public Functions

SymbolDetails
GetObservationSpace_ImplementationGet the observation space for this sensor.
GenerateRayEndpointsGenerate the endpoints of the rays to be cast.
AppendEmptyTagsAdd empty tags to the observation for rays that miss.
HandleRayMissHelper function for appending observation data when a ray hits nothing.
HandleRayHitHandle a successful ray trace and append observation data.
CollectObservations_ImplementationCollect observations about the environment state by casting rays.
GenerateIdGenerate a unique ID string for this sensor.

GetObservationSpace_Implementation

virtual void GetObservationSpace_Implementation(
FInstancedStruct &OutObservationSpace) const override

Get the observation space for this sensor.

Returns a BoxSpace with dimensions for each ray’s observation data:

  • One dimension per tracked tag (1-hot encoded)

  • One dimension for hit/miss (1.0 if hit, 0.0 if miss)

  • One dimension for normalized hit distance (0.0 to 1.0) All dimensions are bounded [0.0, 1.0].

Parameters

OutObservationSpace – [out] The observation space definition to be populated

#DirectionNameTypeDescription
1OutObservationSpaceFInstancedStruct &The observation space definition to be populated

Attributes: const, virtual

Source: Source/Schola/Interactors/Public/Sensors/RayCastSensor.h

Implementation: Source/Schola/Interactors/Private/Sensors/RayCastSensor.cpp

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.

Distributes ray endpoints evenly across the specified angle range. Handles special case of 360 degrees to avoid overlapping rays. Applies transform and offset to position rays in world space.

Parameters

  • InNumRays – [in] The number of rays to generate

  • InRayDegrees – [in] The angle between the first and last ray

  • InBaseEnd – [in] The base endpoint of the rays before rotation

  • InStart – [in] The start point for all rays

  • InBaseTransform – [in] A transform to apply to the generated endpoints

  • InEndOffset – [in] An offset to apply to the end points of the rays

  • OutRayEndpoints – [out] Array to be populated with ray endpoint positions

#DirectionNameTypeDescription
1InNumRaysint32The number of rays to generate
2InRayDegreesfloatThe angle between the first and last ray
3InBaseEndFVectorThe base endpoint of the rays before rotation
4InStartFVectorThe start point for all rays
5InBaseTransformFTransformA transform to apply to the generated endpoints
6InEndOffsetFVectorAn offset to apply to the end points of the rays
7OutRayEndpointsTArray< FVector > &Array to be populated with ray endpoint positions

Source: Source/Schola/Interactors/Public/Sensors/RayCastSensor.h

Implementation: Source/Schola/Interactors/Private/Sensors/RayCastSensor.cpp

AppendEmptyTags

void AppendEmptyTags(FBoxPoint &OutObservations)

Add empty tags to the observation for rays that miss.

Appends zeros for each tracked tag, representing no tag matches.

Parameters

OutObservations – [inout] The observations to append the empty tag values to

#DirectionNameTypeDescription
1OutObservationsFBoxPoint &The observations to append the empty tag values to

Source: Source/Schola/Interactors/Public/Sensors/RayCastSensor.h

Implementation: Source/Schola/Interactors/Private/Sensors/RayCastSensor.cpp

HandleRayMiss

void HandleRayMiss(FBoxPoint &OutObservations, const FVector &InStart,
const FVector &InEnd)

Helper function for appending observation data when a ray hits nothing.

Appends empty tags, hit flag (0.0), and distance (0.0) to observations. Optionally draws debug visualization.

Parameters

  • OutObservations – [inout] The observations to append the results to

  • InStart – [in] The start point of the ray

  • InEnd – [in] The end point of the ray

#DirectionNameTypeDescription
1OutObservationsFBoxPoint &The observations to append the results to
2InStartconst FVector &The start point of the ray
3InEndconst FVector &The end point of the ray

Source: Source/Schola/Interactors/Public/Sensors/RayCastSensor.h

Implementation: Source/Schola/Interactors/Private/Sensors/RayCastSensor.cpp

HandleRayHit

void HandleRayHit(const FHitResult &InHitResult, FBoxPoint &OutObservations,
const FVector &InStart)

Handle a successful ray trace and append observation data.

Checks the hit actor’s tags against TrackedTags and appends a 1-hot encoding. Appends hit flag (1.0) and normalized hit distance. Optionally draws debug visualization.

Parameters

  • InHitResult – [in] The result of the ray trace containing hit information

  • OutObservations – [inout] The observations to append the results to

  • InStart – [in] The start point of the ray

#DirectionNameTypeDescription
1InHitResultconst FHitResult &The result of the ray trace containing hit information
2OutObservationsFBoxPoint &The observations to append the results to
3InStartconst FVector &The start point of the ray

Source: Source/Schola/Interactors/Public/Sensors/RayCastSensor.h

Implementation: Source/Schola/Interactors/Private/Sensors/RayCastSensor.cpp

CollectObservations_Implementation

virtual void
CollectObservations_Implementation(FInstancedStruct &OutObservations) override

Collect observations about the environment state by casting rays.

Generates ray endpoints, performs line traces, and processes hit/miss results. The resulting BoxPoint contains flattened data for all rays.

Parameters

OutObservations – [out] A BoxPoint that will be populated with ray sensor data

#DirectionNameTypeDescription
1OutObservationsFInstancedStruct &A BoxPoint that will be populated with ray sensor data

Attributes: virtual

Source: Source/Schola/Interactors/Public/Sensors/RayCastSensor.h

Implementation: Source/Schola/Interactors/Private/Sensors/RayCastSensor.cpp

GenerateId

FString GenerateId() const

Generate a unique ID string for this sensor.

Returns:

FString describing the sensor configuration (e.g., “Ray_Num_8_Deg_90.00_Max_4096.00_ECC_Camera_Tags_Enemy_Wall”)

Attributes: const

Source: Source/Schola/Interactors/Public/Sensors/RayCastSensor.h

Implementation: Source/Schola/Interactors/Private/Sensors/RayCastSensor.cpp


Public Members

SymbolDetails
RayLengthSphere radius for debug visualization at hit points.
CollisionChannelThe collision channel to use for the raycast.
bDrawDebugLinesDoes this sensor draw debug lines/spheres during runtime.
bTraceComplexShould the sensor trace against complex collision.
NumRaysThe number of rays to fire.
RayDegreesThe angle between the first and last ray.
TrackedTagsActor tags that are checked on raycast collision.
RayEndOffsetA position adjustment that is applied to end points of the generated ray trajectories.
DebugHitColorDebug color for ray hit (when ray intersects an object).
DebugMissColorDebug color for ray miss (when ray hits nothing).

RayLength

float RayLength = 4096.f

Sphere radius for debug visualization at hit points.

The baseline length of each ray. Will be adjusted by the scale component of RayTransform.


CollisionChannel

TEnumAsByte<ECollisionChannel> CollisionChannel

The collision channel to use for the raycast.

Determines what types of objects the rays can hit.


bDrawDebugLines

bool bDrawDebugLines = false

Does this sensor draw debug lines/spheres during runtime.

Useful for visualizing ray directions and hits.


bTraceComplex

bool bTraceComplex = false

Should the sensor trace against complex collision.

If false, uses simple collision shapes.


NumRays

int32 NumRays = 2

The number of rays to fire.

Rays are distributed evenly across RayDegrees.


RayDegrees

float RayDegrees = 90.0f

The angle between the first and last ray.

Special case of 360 degrees creates a full circle.


TrackedTags

TArray<FName> TrackedTags

Actor tags that are checked on raycast collision.

Included in observations as a 1-hot vector per ray.


RayEndOffset

FVector RayEndOffset

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

Useful for fine-tuning ray placement.


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).