I’ve been researching this for days, anyone know how to allow for AI Perception’s Sight to use a custom value for Strength rather than just “1” using C++? Would I need to set up the AISightTargetInterface in any way, if so, how?
Any help would be appreciated !
I found out how to do it! This works on Unreal Engine 4.19.2, this is the answer for anyone else with the same question.
Add this to your perceived pawn header file:
#include "Runtime/AIModule/Classes/Perception/AISightTargetInterface.h"
Make IAISightTargetInterface public in your class header file:
class YOUR_GAME_API APawn: public ACharacter, public IAISightTargetInterface
Expose “CanBeSeenFrom” Function under public in your header file:
public:
// Sets default values for this character's properties
APawn();
virtual bool CanBeSeenFrom(const FVector& ObserverLocation, FVector& OutSeenLocation, int32& NumberOfLoSChecksPerformed, float& OutSightStrength, const AActor* IgnoreActor = NULL) const;
Then in your CPP file, add this:
bool APawn::CanBeSeenFrom(const FVector& ObserverLocation, FVector& OutSeenLocation, int32& NumberOfLoSChecksPerformed, float& OutSightStrength, const AActor* IgnoreActor) const
{
static const FName NAME_AILineOfSight = FName(TEXT("TestPawnLineOfSight"));
FHitResult HitResult;
const bool bHit = GetWorld()->LineTraceSingleByObjectType(HitResult, ObserverLocation, GetActorLocation(), FCollisionObjectQueryParams(ECC_WorldStatic), FCollisionQueryParams(NAME_AILineOfSight, true, IgnoreActor));
NumberOfLoSChecksPerformed++;
// Add any other checks you want to perform here
// ...
if (bHit == false || (HitResult.Actor.IsValid() && HitResult.Actor->IsOwnedBy(this)))
{
OutSeenLocation = GetActorLocation();
OutSightStrength = //YOUR CUSTOM VALUE GOES HERE;
}
OutSightStrength = 0;
return false;
}