Detect when AI Perception loses sight of the player?

I have watched all the you tube videos on the AI perception component and have got it to detect the player successfully but can’t work out how the lose sight part works. I just need a simple blueprint that will detect when the AI can no longer see the player with a boolean output so I can change the behaviour tree. Any ideas?

2 Likes

You could use the GetActorsPerception-node and use the “Return Value”.
True=Sensed
False=Not Sensed

@anonymous_user_618b1a90’s answer is not quite correct. GetActorsPerception will return false only if given actor was never perceived. To see if you lost perception of an actor you need something like [this][1]

Mind this setup assumes you have only one sense specified (sight).

Cheers,

–mieszko

2 Likes

Ok great thanks for the help I’ll have a go at this later and let you know if it works!

it works perfectly!!! been trying to do this for 2 days its been driving me crazy! I’m not sure how it works but it does :slight_smile:

Oh thanks MieszkoZ I didnt know that…now you pushed me back to my perception BPs :frowning:

I’ll be adding a lot more convenient notifications for 4.9, so it’s going to get easier :slight_smile:

Hey, im trying to replicate this. But i cant conect the “get AI Perception Component” to my AI Control (self) . And in the image you share, i cant see where is it conected. where i have to conect that node?
Thanks

Hey, this is what mine looks like. This is on the AIController blueprint.

This helped me a lot. In case someone needs it in c++ :

 FActorPerceptionBlueprintInfo Info;
    				GetAIPerceptionComponent()->GetActorsPerception(PlayerPawn, Info);
    				
    				if (Info.LastSensedStimuli.Num() > 0) {
    					const FAIStimulus Stimulus = Info.LastSensedStimuli[0];
    
    					if (Stimulus.WasSuccessfullySensed()) {
    						//Player in sight
    					}
    					else {
    						//Player out of sight
    					}
    				}
2 Likes

I tested this with two AI enemies, and they will block the sight to each other and one will return “lost sight” to the target (Player Character) even it is very closed to the target with Vision Angle 180 degree.
Anyone happened the same? Or, did I miss something I gonna setup? please advise. Thank you.

1 Like

same problem here.

Hi @mieszkoz !

I have problem. With this solution I have any output - always false even when ai see player (event). I tried to call it from ai controller and from ai blueprint - everything is fine, but no success. I have also EQS Query and it working (see can’t see), however I need simple see test from bp and this is very important.

Maybe I miss some settings on sensing?

Thx’s for any help!

ps. Here my log:

Blueprint Runtime Error: Attempted to access index 0 from array LastSensedStimuli of length 0! from function: 'ExecuteUbergraph_OperatorBP' from node: Set PlayerInSight in graph: EventGraph in object: OperatorBP with description: Attempted to access index 0 from array LastSensedStimuli of length 0!

looking for solution for this same problem too

I’m very confused how this can be a solution, the code says to Broadcast OnPerceptionUpdated if the UpdatedActors is greater than 0. If Sight is lost or all senses do not detected something aka sight lost aka false, UpdatedActors will be 0 and the OnPerceptionUpdated event should not fire. So if it does not fire when the sense is false, it will never be able to fire and get a false value for a sense. The only exception being if you have two senses, and one sense fires true while the other did not fire resulting in a false.