Class URayCastSensor
Class URayCastSensor
- Defined in File RayCastSensor.h
Inheritance Relationships
Base Types
-
public USceneComponent -
public IScholaSensor(Class IScholaSensor)
class URayCastSensor : public USceneComponent, public IScholaSensorSource: 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
| Symbol | Details |
|---|---|
GetObservationSpace_Implementation | Get the observation space for this sensor. |
GenerateRayEndpoints | Generate the endpoints of the rays to be cast. |
AppendEmptyTags | Add empty tags to the observation for rays that miss. |
HandleRayMiss | Helper function for appending observation data when a ray hits nothing. |
HandleRayHit | Handle a successful ray trace and append observation data. |
CollectObservations_Implementation | Collect observations about the environment state by casting rays. |
GenerateId | Generate a unique ID string for this sensor. |
GetObservationSpace_Implementation
virtual void GetObservationSpace_Implementation( FInstancedStruct &OutObservationSpace) const overrideGet 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
| # | Direction | Name | Type | Description |
|---|---|---|---|---|
| 1 | — | OutObservationSpace | FInstancedStruct & | 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
| # | Direction | Name | Type | Description |
|---|---|---|---|---|
| 1 | — | InNumRays | int32 | The number of rays to generate |
| 2 | — | InRayDegrees | float | The angle between the first and last ray |
| 3 | — | InBaseEnd | FVector | The base endpoint of the rays before rotation |
| 4 | — | InStart | FVector | The start point for all rays |
| 5 | — | InBaseTransform | FTransform | A transform to apply to the generated endpoints |
| 6 | — | InEndOffset | FVector | An offset to apply to the end points of the rays |
| 7 | — | OutRayEndpoints | TArray< 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
| # | Direction | Name | Type | Description |
|---|---|---|---|---|
| 1 | — | OutObservations | FBoxPoint & | 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
| # | Direction | Name | Type | Description |
|---|---|---|---|---|
| 1 | — | OutObservations | FBoxPoint & | The observations to append the results to |
| 2 | — | InStart | const FVector & | The start point of the ray |
| 3 | — | InEnd | const 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
| # | Direction | Name | Type | Description |
|---|---|---|---|---|
| 1 | — | InHitResult | const FHitResult & | The result of the ray trace containing hit information |
| 2 | — | OutObservations | FBoxPoint & | The observations to append the results to |
| 3 | — | InStart | const 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 voidCollectObservations_Implementation(FInstancedStruct &OutObservations) overrideCollect 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
| # | Direction | Name | Type | Description |
|---|---|---|---|---|
| 1 | — | OutObservations | FInstancedStruct & | 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() constGenerate 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
| Symbol | Details |
|---|---|
RayLength | Sphere radius for debug visualization at hit points. |
CollisionChannel | The collision channel to use for the raycast. |
bDrawDebugLines | Does this sensor draw debug lines/spheres during runtime. |
bTraceComplex | Should the sensor trace against complex collision. |
NumRays | The number of rays to fire. |
RayDegrees | The angle between the first and last ray. |
TrackedTags | Actor tags that are checked on raycast collision. |
RayEndOffset | A position adjustment that is applied to end points of the generated ray trajectories. |
DebugHitColor | Debug color for ray hit (when ray intersects an object). |
DebugMissColor | Debug color for ray miss (when ray hits nothing). |
RayLength
float RayLength = 4096.fSphere 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> CollisionChannelThe collision channel to use for the raycast.
Determines what types of objects the rays can hit.
bDrawDebugLines
bool bDrawDebugLines = falseDoes this sensor draw debug lines/spheres during runtime.
Useful for visualizing ray directions and hits.
bTraceComplex
bool bTraceComplex = falseShould the sensor trace against complex collision.
If false, uses simple collision shapes.
NumRays
int32 NumRays = 2The number of rays to fire.
Rays are distributed evenly across RayDegrees.
RayDegrees
float RayDegrees = 90.0fThe angle between the first and last ray.
Special case of 360 degrees creates a full circle.
TrackedTags
TArray<FName> TrackedTagsActor tags that are checked on raycast collision.
Included in observations as a 1-hot vector per ray.
RayEndOffset
FVector RayEndOffsetA position adjustment that is applied to end points of the generated ray trajectories.
Useful for fine-tuning ray placement.
DebugHitColor
FColor DebugHitColor = FColor::GreenDebug color for ray hit (when ray intersects an object).
DebugMissColor
FColor DebugMissColor = FColor::RedDebug color for ray miss (when ray hits nothing).