PeripheralVisionAngle

PeripheralVisionAngle

#Overview

name: PeripheralVisionAngle

The value of this variable can be defined or overridden in .ini config files. 1 .ini config file referencing this setting variable.

It is referenced in 4 C++ source files.

#Summary

#Usage in the C++ source code

The purpose of PeripheralVisionAngle is to define the field of view for AI-controlled pawns in Unreal Engine 5. It specifically determines how far to the side an AI can see, measured in degrees.

This setting variable is primarily used in the AI Module, specifically within the PawnSensingComponent. The PawnSensingComponent is responsible for handling perception-related functionality for AI-controlled pawns.

The value of PeripheralVisionAngle is initially set in the constructor of the UPawnSensingComponent class with a default value of 90 degrees. It can be modified at runtime using the SetPeripheralVisionAngle function, which is exposed as a BlueprintCallable function for easy access in Blueprint scripts.

PeripheralVisionAngle interacts closely with another variable called PeripheralVisionCosine. When PeripheralVisionAngle is set or changed, PeripheralVisionCosine is automatically calculated as the cosine of PeripheralVisionAngle (converted to radians). This pre-computed value is likely used for performance optimization in vision checks.

Developers should be aware that changing PeripheralVisionAngle will automatically update PeripheralVisionCosine. They should use the SetPeripheralVisionAngle function to modify this value rather than changing it directly, to ensure proper updating of related variables.

Best practices when using this variable include:

  1. Use the SetPeripheralVisionAngle function to modify the value at runtime.
  2. Consider the performance implications of very large angles, as they may require more extensive checks in the game world.
  3. Balance the value with other sensing parameters like SightRadius for realistic AI behavior.
  4. Use the GetPeripheralVisionAngle function to retrieve the current value if needed in code or blueprints.
  5. Remember that this value affects the AI’s ability to detect objects or other pawns, so it should be tuned carefully based on the game’s design and difficulty requirements.

#Setting Variables

#References In INI files

Location: <Workspace>/Engine/Config/BaseGame.ini:190, section: [/Script/AIModule.AIPerceptionComponent]

#References in C++ code

#Callsites

This variable is referenced in the following C++ source code:

#Loc: <Workspace>/Engine/Source/Runtime/AIModule/Classes/Perception/PawnSensingComponent.h:59

Scope (from outer to inner):

file
class        class UPawnSensingComponent : public UActorComponent

Source code excerpt:

	AIMODULE_API virtual void SetSensingUpdatesEnabled(const bool bEnabled);

	/** Sets PeripheralVisionAngle. Calculates PeripheralVisionCosine from PeripheralVisionAngle */
	UFUNCTION(BlueprintCallable, BlueprintAuthorityOnly, Category="AI|Components|PawnSensing")
	AIMODULE_API virtual void SetPeripheralVisionAngle(const float NewPeripheralVisionAngle);

	UFUNCTION(BlueprintCallable, Category="AI|Components|PawnSensing")
	AIMODULE_API float GetPeripheralVisionAngle() const;

#Loc: <Workspace>/Engine/Source/Runtime/AIModule/Classes/Perception/PawnSensingComponent.h:176

Scope (from outer to inner):

file
class        class UPawnSensingComponent : public UActorComponent

Source code excerpt:

	/** How far to the side AI can see, in degrees. Use SetPeripheralVisionAngle to change the value at runtime. */
	UPROPERTY(EditAnywhere, BlueprintReadOnly, Category=AI)
	float PeripheralVisionAngle;

	/** Cosine of limits of peripheral vision. Computed from PeripheralVisionAngle. */
	UPROPERTY()
	float PeripheralVisionCosine;
};



inline float UPawnSensingComponent::GetPeripheralVisionAngle() const
{
	return PeripheralVisionAngle;
}

inline float UPawnSensingComponent::GetPeripheralVisionCosine() const
{
	return PeripheralVisionCosine;
}

#Loc: <Workspace>/Engine/Source/Runtime/AIModule/Private/Perception/PawnSensingComponent.cpp:22

Scope (from outer to inner):

file
function     UPawnSensingComponent::UPawnSensingComponent

Source code excerpt:

	HearingThreshold = 1400.0f;
	SightRadius = 5000.0f;
	PeripheralVisionAngle = 90.f;
	PeripheralVisionCosine = FMath::Cos(FMath::DegreesToRadians(PeripheralVisionAngle));
	
	SensingInterval = 0.5f;
	HearingMaxSoundAge = 1.f;

	bOnlySensePlayers = true;
	bHearNoises = true;

#Loc: <Workspace>/Engine/Source/Runtime/AIModule/Private/Perception/PawnSensingComponent.cpp:42

Scope (from outer to inner):

file
function     void UPawnSensingComponent::SetPeripheralVisionAngle

Source code excerpt:

void UPawnSensingComponent::SetPeripheralVisionAngle(const float NewPeripheralVisionAngle)
{
	PeripheralVisionAngle = NewPeripheralVisionAngle;
	PeripheralVisionCosine = FMath::Cos(FMath::DegreesToRadians(PeripheralVisionAngle));
}


void UPawnSensingComponent::InitializeComponent()
{
	Super::InitializeComponent();
	SetPeripheralVisionAngle(PeripheralVisionAngle);
	
	if (bEnableSensingUpdates)
	{
		bEnableSensingUpdates = false; // force an update
		SetSensingUpdatesEnabled(true);
	}