Used to customize how AISense Sight checks the visibility of an actor.


Override CanBeSeenFrom. A basic implementation as follows:

Note: Below implementation is still functional as of 5.2, but there’s a new override you should use instead:

virtual UAISense_Sight::EVisibilityResult CanBeSeenFrom(const FCanBeSeenFromContext& Context, FVector& OutSeenLocation, int32& OutNumberOfLoSChecksPerformed, int32& OutNumberOfAsyncLosCheckRequested, float& OutSightStrength, int32* UserData = nullptr, const FOnPendingVisibilityQueryProcessedDelegate* Delegate = nullptr)

It works mostly the same, but check the IAISightTargetInterface.h file for details on how the EVisibilityResult is intended to be used.

	//This gets the sight trace channel that's configured in project settings
	DefaultSightCollisionChannel = GET_AI_CONFIG_VAR(DefaultSightCollisionChannel);
bool AMyCharacter::CanBeSeenFrom(const FVector& ObserverLocation, FVector& OutSeenLocation, int32& NumberOfLoSChecksPerformed, float& OutSightStrength, const AActor* IgnoreActor) const
	FHitResult HitResult;
	//check against location first - this is about in the center of the character
	bool IsHit = GetWorld()->LineTraceSingleByChannel(HitResult, ObserverLocation, GetActorLocation()
        , DefaultSightCollisionChannel, FCollisionQueryParams(SCENE_QUERY_STAT(AILineOfSight), true, IgnoreActor));
	NumberOfLoSChecksPerformed = 1;
	if(!IsHit || HitResult.GetActor() != this)
		//if we don't see the center of the character, look for the camera location which is where the
		//player's point of view is, which allows the enemies to see the player in a more reasonable fashion
		//if the body is partially obscured
		IsHit = GetWorld()->LineTraceSingleByChannel(HitResult, ObserverLocation, Camera->GetComponentLocation()
			, DefaultSightCollisionChannel, FCollisionQueryParams(SCENE_QUERY_STAT(AILineOfSight), true, IgnoreActor));
	OutSeenLocation = HitResult.Location;
	OutSightStrength = 1;
	return IsHit && HitResult.GetActor() == this;

The DefaultSightCollisionChannel value assigned in the sample constructor is the default sight channel which can be adjusted from project settings under the AI settings.