UPawnSensingComponent

SensingComponent encapsulates sensory (ie sight and hearing) settings and functionality for an Actor, allowing the actor to see/hear Pawns in the world.

Choose your operating system:

Windows

macOS

Linux

Inheritance Hierarchy

References

Module

AIModule

Header

/Engine/Source/Runtime/AIModule/Classes/Perception/PawnSensingComponent.h

Include

#include "Perception/PawnSensingComponent.h"

Syntax

class UPawnSensingComponent : public UActorComponent

Remarks

SensingComponent encapsulates sensory (ie sight and hearing) settings and functionality for an Actor, allowing the actor to see/hear Pawns in the world. It does nothing on network clients.

Variables

Name Description

Public variable

uint32: 1

 

bEnableSensingUpdates

If true, component will perform sensing updates.

Public variable

uint32: 1

 

bHearNoises

If true, we will perform audibility tests and will be notified when a Pawn makes a noise that can be heard.

Public variable

uint32: 1

 

bOnlySensePlayers

If true, will only sense player-controlled pawns in the world. Default: true

Public variable

uint32: 1

 

bSeePawns

If true, we will perform visibility tests and will trigger notifications when a Pawn is visible.

Public variable

float

 

HearingMaxSoundAge

Max age of sounds we can hear. Should be greater than SensingInterval, or you might miss hearing some sounds!

Public variable

float

 

HearingThreshold

Max distance at which a makenoise(1.0) loudness sound can be heard, regardless of occlusion

Public variable

float

 

LOSHearingThreshold

Max distance at which a makenoise(1.0) loudness sound can be heard if unoccluded (LOSHearingThreshold should be > HearingThreshold)

Public variable

FHearNoiseDeleg...

 

OnHearNoise

Delegate to execute when we hear a noise from a Pawn's PawnNoiseEmitterComponent.

Public variable

FSeePawnDelegat...

 

OnSeePawn

Delegate to execute when we see a Pawn.

Protected variable

float

 

PeripheralVisionAngle

How far to the side AI can see, in degrees.

Protected variable

float

 

PeripheralVisionCosine

Cosine of limits of peripheral vision. Computed from PeripheralVisionAngle.

Public variable

float

 

SensingInterval

Amount of time between pawn sensing updates.

Public variable

float

 

SightRadius

Maximum sight distance.

Protected variable

FTimerHandle

 

TimerHandle_OnTimer

Handle for efficient management of OnTimer timer

Constructors

Name Description

Public function

UPawnSensingComponent

(
    const FObjectInitializer& ObjectIn...
)

Functions

Name Description

Protected function Virtual

void

 

BroadcastOnHearLocalNoise

(
    APawn& Instigator,
    const FVector& Location,
    float Volume
)

Broadcasts notification that our sensor hears a noise made local to a Pawn's position, using the OnHearNoise delegates.

Protected function Virtual

void

 

BroadcastOnHearRemoteNoise

(
    APawn& Instigator,
    const FVector& Location,
    float Volume
)

Broadcasts notification that our sensor hears a noise made remotely from a Pawn's position, using the OnHearNoise delegates.

Protected function Virtual

void

 

BroadcastOnSeePawn

(
    APawn& Pawn
)

Broadcasts notification that our sensor sees a Pawn, using the OnSeePawn delegates.

Public function Virtual Const

bool

 

CanHear

(
    const FVector& NoiseLoc,
    float Loudness,
    bool bFailedLOS
)

True if sensor can hear this noise.

Public function Virtual Const

bool

 

CanSenseAnything()

Are we capable of sensing anything (and do we have any callbacks that care about sensing)? If so UpdateAISensing() will be called every sensing interval.

Public function Virtual Const

bool

 

CouldSeePawn

(
    const APawn* Other,
    bool bMaySkipChecks
)

Chance of seeing other pawn decreases with increasing distance or angle in peripheral vision

Public function Const

float

 

GetPeripheralVisionAngle()

Public function Const

float

 

GetPeripheralVisionCosine()

Protected function Const

AActor *

 

GetSensorActor()

Protected function Const

AController ...

 

GetSensorController()

Public function Virtual Const

FVector

 

GetSensorLocation()

Get position where hearing/seeing occurs (i.e. ear/eye position).

Public function Virtual Const

FRotator

 

GetSensorRotation()

Get the rotation of this sensor. We need this for the sight component

Public function Virtual Const

bool

 

HasLineOfSightTo

(
    const AActor* Other
)

Check line to other actor.

Public function Const

bool

 

IsNoiseRelevant

(
    const APawn& Pawn,
    const UPawnNoiseEmitterComponent& ...,
    bool bSourceWithinNoiseEmitter
)

Test whether the noise is loud enough and recent enough to care about.

Public function Virtual Const

bool

 

IsSensorActor

(
    const AActor* Actor
)

Is the given actor our owner? Used to ensure that we are not trying to sense our self / our owner.

Protected function Virtual

void

 

OnTimer()

Update function called on timer intervals.

Protected function Virtual

void

 

SensePawn

(
    APawn& Pawn
)

See if there are interesting sounds and sights that we want to detect, and respond to them if so.

Public function Virtual

void

 

SetPeripheralVisionAngle

(
    const float NewPeripheralVisionAngl...
)

Sets PeripheralVisionAngle. Calculates PeripheralVisionCosine from PeripheralVisionAngle

Public function Virtual

void

 

SetSensingInterval

(
    const float NewSensingInterval
)

Changes the SensingInterval.

Public function Virtual

void

 

SetSensingUpdatesEnabled

(
    const bool bEnabled
)

Enables or disables sensing updates. The timer is reset in either case.

Protected function Virtual

void

 

SetTimer

(
    const float TimeDelay
)

Modify the timer to fire in TimeDelay seconds. A value <= 0 disables the timer.

Public function Virtual Const

bool

 

ShouldCheckAudibilityOf

(
    APawn* Pawn
)

Returns true if we should check whether we can hear the given Pawn (because we are able to hear, and the Pawn has the correct team relationship to us)

Public function Virtual Const

bool

 

ShouldCheckVisibilityOf

(
    APawn* Pawn
)

Returns true if we should check whether the given Pawn is visible (because we can see things, the Pawn is not hidden, and if the Pawn is a player and we only see players)

Protected function Virtual

void

 

UpdateAISensing()

Calls SensePawn on any Pawns that we are allowed to sense.

Overridden from UActorComponent

Name Description

Public function Virtual

void

 

InitializeComponent()

Initializes the component.

Classes