How to Update AI Perception Manually?

How to call AI onTargetPerceptionUpdated if the player is already in view? I need the AI to turn on by script, but it does not react until the player exits and re-enters the field of view.
For instance i have AI that behaves neutral to player, but when he does something wrong, ai turns aggressive on player.

Hey @Hazmat0S!

So this kind of thing is less AI reliant and more base logic. You’ll want to use things like DoOnce, Gate, etc.

What I would do is upon notice, open a gate on the “Does not see” path, turning a bool True, such as “Seen”. Then on the “SeesPlayer” path, check if “Seen” is true. So

On seen: Check “SawPlayer” variable (Keep it false as default.) Since it will be false first, take false path to open Gate on “Not Seen”.
Unseen: attempt Gate. If gate Open, Set “SawPlayer” to True.
On seen 2+ times: Check “SawPlayer” again, and since it should now be true, execute aggressive action.

:slight_smile:

Instead of hiding the player until they do something wrong, probably better for the player to “broadcast” their action to nearby pawns.

Like, if you have a “steal item” function or whatever on the player, have it sphere trace for pawns and call a function on them (or use an interface message) to let them know they witnessed a crime or whatevs. This function would then decide how to react, and add the player as a target on the AI’s behavior/state tree if the action should aggro them.

1 Like

Try “Request Stimuli Listener Update”. You can find its description under “Perception Function Calls” in the AI Perception documentation.
AI Perception | Unreal Engine 4.27 Documentation

1 Like

Thank you for actually answering the question. I also need to update the perception manually, and this is the first thread that comes up in a search. And then the first two people didn’t answer the question, but told the OP completely different things to do.