SightRadius
SightRadius
#Overview
name: SightRadius
The value of this variable can be defined or overridden in .ini config files. 2
.ini config files referencing this setting variable.
It is referenced in 9
C++ source files.
#Summary
#Usage in the C++ source code
The purpose of SightRadius is to define the maximum distance at which an AI-controlled entity can detect or “see” other objects or actors in the game world. It is primarily used in the AI perception and sensing systems of Unreal Engine 5.
This setting variable is utilized by several Unreal Engine subsystems and modules, primarily within the AI and perception-related components. The main modules that rely on this variable are:
- AIModule
- Perception system
- PawnSensing component
- MLAdapter plugin (for AI-related machine learning adaptations)
The value of this variable is typically set in the following ways:
- Through the Unreal Engine editor in the properties panel of relevant components
- In C++ code, either during component initialization or runtime
- Via Blueprint nodes that expose this property
SightRadius often interacts with other variables such as:
- LoseSightRadius: The maximum distance to see a target that has already been detected
- PeripheralVisionAngleDegrees: The angle of peripheral vision
- NearClippingRadius: The minimum distance for sight detection
Developers should be aware of the following when using this variable:
- SightRadius is measured in centimeters (UE5’s default unit)
- It affects performance, as larger values require more extensive checks in the game world
- It’s used in both 2D (cylindrical) and 3D (spherical) space depending on the context
Best practices when using this variable include:
- Balance it with performance considerations; avoid unnecessarily large values
- Use it in conjunction with other sensing parameters for more realistic AI behavior
- Consider adjusting it dynamically based on game conditions (e.g., lighting, weather)
- Ensure it’s appropriate for the scale of your game world and the speed of moving objects
- Test thoroughly to ensure desired AI behavior across various scenarios
#Setting Variables
#References In INI files
Location: <Workspace>/Engine/Config/BaseGame.ini:188, section: [/Script/AIModule.AIPerceptionComponent]
- INI Section:
/Script/AIModule.AIPerceptionComponent
- Raw value:
3000
- Is Array:
False
Location: <Workspace>/Engine/Config/BaseGame.ini:202, section: [/Script/AIModule.AISenseConfig_Sight]
- INI Section:
/Script/AIModule.AISenseConfig_Sight
- Raw value:
3000
- Is Array:
False
#References in C++ code
#Callsites
This variable is referenced in the following C++ source code:
#Loc: <Workspace>/Engine/Plugins/AI/MLAdapter/Source/MLAdapter/Private/Sensors/MLAdapterSensor_AIPerception.cpp:116
Scope (from outer to inner):
file
function void UMLAdapterSensor_AIPerception::OnAvatarSet
Source code excerpt:
UAISenseConfig_Sight* SightConfig = NewObject<UAISenseConfig_Sight>(this, UAISenseConfig_Sight::StaticClass(), TEXT("UAISenseConfig_Sight"));
check(SightConfig);
SightConfig->SightRadius = 50000;
SightConfig->LoseSightRadius = 53000;
SightConfig->PeripheralVisionAngleDegrees = PeripheralVisionAngleDegrees;
SightConfig->AutoSuccessRangeFromLastSeenLocation = FAISystem::InvalidRange;
SightConfig->SetMaxAge(MaxStimulusAge);
PerceptionComponent->ConfigureSense(*SightConfig);
PerceptionComponent->RegisterComponent();
#Loc: <Workspace>/Engine/Source/Editor/ComponentVisualizers/Private/SensingComponentVisualizer.cpp:38
Scope (from outer to inner):
file
function void FSensingComponentVisualizer::DrawVisualization
Source code excerpt:
// Sight
if (Senses->SightRadius > 0.0f)
{
TArray<FVector> Verts;
DrawWireCone(PDI, Verts, Transform, Senses->SightRadius, Senses->GetPeripheralVisionAngle(), 10, FColor::Green, SDPG_World);
}
}
}
}
#Loc: <Workspace>/Engine/Source/Runtime/AIModule/Classes/Perception/AISenseConfig_Sight.h:25
Scope (from outer to inner):
file
class class UAISenseConfig_Sight : public UAISenseConfig
Source code excerpt:
/** Maximum sight distance to notice a target. */
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Sense", config, meta = (UIMin = 0.0, ClampMin = 0.0, Units="Centimeters"))
float SightRadius;
/** Maximum sight distance to see target that has been already seen. */
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Sense", config, meta = (UIMin = 0.0, ClampMin = 0.0, Units="Centimeters"))
float LoseSightRadius;
/** How far to the side AI can see, in degrees. Use SetPeripheralVisionAngle to change the value at runtime.
#Loc: <Workspace>/Engine/Source/Runtime/AIModule/Classes/Perception/PawnSensingComponent.h:35
Scope (from outer to inner):
file
class class UPawnSensingComponent : public UActorComponent
Source code excerpt:
/** Maximum sight distance. */
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category=AI)
float SightRadius;
/** Amount of time between pawn sensing updates. Use SetSensingInterval() to adjust this at runtime. A value <= 0 prevents any updates. */
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category=AI)
float SensingInterval;
// Max age of sounds we can hear. Should be greater than SensingInterval, or you might miss hearing some sounds!
#Loc: <Workspace>/Engine/Source/Runtime/AIModule/Private/Perception/AISense.cpp:218
Scope (from outer to inner):
file
function void UAISenseConfig_Sight::DescribeSelfToGameplayDebugger
Source code excerpt:
FString::Printf(TEXT("%s: {%s}%s {white}rangeIN:{%s} %.2f (%s) {white} rangeOUT:{%s} %.2f (%s)"), *GetSenseName(),
*GetDebugColor().ToString(), *DescribeColorHelper(GetDebugColor()),
*SightRangeColor.ToString(), SightRadius, *DescribeColorHelper(SightRangeColor),
*LoseSightRangeColor.ToString(), LoseSightRadius, *DescribeColorHelper(LoseSightRangeColor))
);
const AActor* BodyActor = PerceptionComponent->GetBodyActor();
if (BodyActor != nullptr)
{
#Loc: <Workspace>/Engine/Source/Runtime/AIModule/Private/Perception/AISense.cpp:229
Scope (from outer to inner):
file
function void UAISenseConfig_Sight::DescribeSelfToGameplayDebugger
Source code excerpt:
DebuggerCategory->AddShape(FGameplayDebuggerShape::MakeCylinder(BodyLocation, LoseSightRadius, 25.0f, LoseSightRangeColor));
DebuggerCategory->AddShape(FGameplayDebuggerShape::MakeCylinder(BodyLocation, SightRadius, 25.0f, SightRangeColor));
const float SightPieLength = FMath::Max(LoseSightRadius, SightRadius) + PointOfViewBackwardOffset;
const FVector RootLocation = BodyLocation - (BodyFacing * PointOfViewBackwardOffset);
const FVector LeftDirection = BodyFacing.RotateAngleAxis(PeripheralVisionAngleDegrees, FVector::UpVector);
const FVector RightDirection = BodyFacing.RotateAngleAxis(-PeripheralVisionAngleDegrees, FVector::UpVector);
DebuggerCategory->AddShape(FGameplayDebuggerShape::MakeSegment(RootLocation + (BodyFacing * NearClippingRadius), RootLocation + (BodyFacing * SightPieLength), SightRangeColor));
DebuggerCategory->AddShape(FGameplayDebuggerShape::MakeSegment(RootLocation + (LeftDirection * NearClippingRadius), RootLocation + (LeftDirection * SightPieLength), SightRangeColor));
DebuggerCategory->AddShape(FGameplayDebuggerShape::MakeSegment(RootLocation + (RightDirection * NearClippingRadius), RootLocation + (RightDirection * SightPieLength), SightRangeColor));
#Loc: <Workspace>/Engine/Source/Runtime/AIModule/Private/Perception/AISense_Sight.cpp:112
Scope (from outer to inner):
file
function UAISense_Sight::FDigestedSightProperties::FDigestedSightProperties
Source code excerpt:
UAISense_Sight::FDigestedSightProperties::FDigestedSightProperties(const UAISenseConfig_Sight& SenseConfig)
{
SightRadiusSq = FMath::Square(SenseConfig.SightRadius + SenseConfig.PointOfViewBackwardOffset);
LoseSightRadiusSq = FMath::Square(SenseConfig.LoseSightRadius + SenseConfig.PointOfViewBackwardOffset);
PointOfViewBackwardOffset = SenseConfig.PointOfViewBackwardOffset;
NearClippingRadiusSq = FMath::Square(SenseConfig.NearClippingRadius);
PeripheralVisionAngleCos = FMath::Cos(FMath::Clamp(FMath::DegreesToRadians(SenseConfig.PeripheralVisionAngleDegrees), 0.f, PI));
AffiliationFlags = SenseConfig.DetectionByAffiliation.GetAsFlags();
// keep the special value of FAISystem::InvalidRange (-1.f) if it's set.
#Loc: <Workspace>/Engine/Source/Runtime/AIModule/Private/Perception/PawnSensingComponent.cpp:21
Scope (from outer to inner):
file
function UPawnSensingComponent::UPawnSensingComponent
Source code excerpt:
LOSHearingThreshold = 2800.f;
HearingThreshold = 1400.0f;
SightRadius = 5000.0f;
PeripheralVisionAngle = 90.f;
PeripheralVisionCosine = FMath::Cos(FMath::DegreesToRadians(PeripheralVisionAngle));
SensingInterval = 0.5f;
HearingMaxSoundAge = 1.f;
#Loc: <Workspace>/Engine/Source/Runtime/AIModule/Private/Perception/PawnSensingComponent.cpp:332
Scope (from outer to inner):
file
function bool UPawnSensingComponent::CouldSeePawn
Source code excerpt:
// check max sight distance
FVector::FReal const SelfToOtherDistSquared = SelfToOther.SizeSquared();
if (SelfToOtherDistSquared > FMath::Square(SightRadius))
{
return false;
}
// may skip if more than some fraction of maxdist away (longer time to acquire)
if (bMaySkipChecks && (FMath::Square(FMath::FRand()) * SelfToOtherDistSquared > FMath::Square(0.4f * SightRadius)))
{
return false;
}
// UE_LOG(LogPath, Warning, TEXT("DistanceToOtherSquared = %f, SightRadiusSquared: %f"), SelfToOtherDistSquared, FMath::Square(SightRadius));
// check field of view
FVector const SelfToOtherDir = SelfToOther.GetSafeNormal();
FVector const MyFacingDir = GetSensorRotation().Vector();
// UE_LOG(LogPath, Warning, TEXT("DotProductFacing: %f, PeripheralVisionCosine: %f"), SelfToOtherDir | MyFacingDir, PeripheralVisionCosine);