Possible bug in AAIController::LineOfSightTo()

Hello everyone,

there seems to be a little bug in the method LineOfSightTo().

Take a look at

bool bHit = GetWorld()->LineTraceTest(ViewPoint, TargetLocation, ECC_Visibility, CollisionParams);
if( !bHit )
{
    return true;
}

Shouldn’t that be

bool bHit = GetWorld()->LineTraceTest(ViewPoint, TargetLocation, ECC_Visibility, CollisionParams);
if( bHit ) // That should be better
{
    return true;
}

?

Disagree, if not hit the target is visible.

Hi Pierdek,

thanks for your answer.
I could be wrong, but as I see it, the trace is checking if the target is visible by using the ECC_Visibility flag. So if there is a blocking hit on the visibility channel, then I have a line of sight.

If there was no hit - then nothing blocks the player view. Nothing wrong here.

Alright, so I’m just stupid now. Thanks for clarifying.

Alright now, I know what my problem was.

Of course that part I mentioned is correct.
Alright so my problem was, that I was not able to check the line of sight to another non-pawn actor.
As I see it, Line of Sight only works for pawns or for actors with a capsule component. I used a box component as the collision primitive.

So for anyone else, who stumbles over the same problem. Use a pawn or a capsule component or another function.