How to tell when a pawn is no longer sensed (pawnsensing)

I’m trying to create an array of pawns that are currently sensed in blueprint, but it seems there is only a “on pawn sensed” and not “on pawn lost”. Unreal clearly internally registers when a pawn is lost, but it can’t figure out how to make it tell me.

Hi there!

Not sure if you’ve found the answer yourself by now, but I spent days trying to work it out!

Turns out all you need to do is set a bool from your OnPawnSee event, run into a sequence, from there have the first pin run to what action you want to preform, mine is to print ‘Sight’ then fire a custom event. On the second pin, have a retriggerable delay of a value higher than your Pawn Sensing Components sensing interval (Default is 0.5 so I set my delay at 0.6), Then have that run into your bool setting it false. Job done!:slight_smile:

Heres a picture to illustrate what I mean
Hope it helps!

3 Likes

Hi!

I have the same problem as the person who started this post.

I’ve tried doing a sphere trace to check if my AI character can see the player in my OnSeePawn event before my AI MoveTo and if it can, it will run towards the player, but it’s kinda broken and the AI can still run towards the player even after the player hides behind walls.

I have seen your solution but I can’t seem to understand how it works, in particular the event “Reset Sense” and why having a retriggerable delay of a value higher than the sensing interval. What is actually in the event that causes the sensing to reset and how does the delay solve the problem?

Hi there!

Sorry, must’ve forgotten the reset sense bit! Also this is going to be really long but bear with me:)

Reset Sense:

All it does is fire the reset pin of a Do Once node (The Do Once node just goes to whatever code you want to run when he sees the player). This is useful if you do not want your action to be performed every sensing interval, and rather once when initially he sees you. So the flow will be the OnSeePawn firing, setting off the custom event Seen Target, then that event running through a Do Once node. I’ve done this because after my Do Once node I have him move from place to place firing a gun with various delays (That code isn’t visible in the picture in case you were confused), but I only want that process to be started once when he sees me, and not every 0.5 seconds that OnSeePawn fires, so Ive used the Do Once node.
The Reset Sense simply resets the Do Once node when the player is out of sight (How it fires at the right time is explained below) meaning when the player is in sight, Seen Target will fire, and be able to pass through the Do Once node again.

Retriggerable Delay:

As to the retriggerable delay, this value must be higher than the pawn sensing interval so that it never fires whilst the pawn is in sight. Every 0.5 seconds the OnSeePawn checks if the player is in sight and fires if true, starting the retriggerable delay to count down from 0.6. Now, once the retriggerable delay gets to 0.1 seconds left, 0.5 seconds has passed and the OnSeePawn event checks if the player is in sight, and if true, fires, resetting the retriggerble delay back to 0.6, meaning the bool ‘See Enemy’ doesnt get set to false.
If however when there is 0.1 seconds left on the retriggerable delay and the OnSeePawn checks if the player is in sight, and returns false, it wont fire. Therefore the retriggerable delay wont be reset and will count down to zero, then firing the bool setting See Enemy to false. See the photo above.

How to use the See Enemy Bool:

To make the Ai stop chasing you when you go out of sight, you need to check the value of the See Enemy bool.
The only way I can think of to do that (My Ai dont chase so its slightly different) would be to have a delay after your Ai Move To node of however many seconds you like (Experiment abit, whatever suits your game best, start at 1 and see how it goes) hooked up to a branch with See Enemy as the condition, if true, have the pin loop back into the Ai move to, if false, have the Ai move to a different location or whatever you’d like to do with him. Below is a quick mock up of what I mean

Hope this helps! I know it was long sorry, let me know how it goes:)

Matt

3 Likes

Cool, pictures didnt work, so helpful…

Where you see alt text 1 look at the seeing reset.png
Where you see alt text 2 look at the stopchase.png

Oh my gosh man. You are a lifesaver! I had to tweak some part of the blueprint to fit, but now it works like a charm! THANK YOU SO, SO MUCH! You don’t know how much this means to me!

You’re Welcome!:slight_smile: Glad I could be of help haha
Anything else you need let me know!

Mate, thankyou for this, works just like I wanted

Works like charm, thank-you!

In my case I have a radius where the enemy can see the player, 10,000.00 units for example, every 100 milliseconds I verify if the player is in that radius, if hes not in the radius I’ll set variable isPawnSensed to false. Because in my case is hard to the enemy see the player, if I base my logic on the PawnSensing Component player again, but not a radius, I wont have too much control over it and I think its not going to feel good to my game.

How do we turn off the pawn sense just during the enemy reaction montage, so they don’t do any actions till after reaction montage is finished? My enemy moves and attacks in the middle of hit reaction montages?

Hi. Perhaps, my solution will help anyone.

  1. In ‘On See Pawn’ I set bool ‘IsSeeingPlayer’ to true for ‘SensingInterval’ seconds. I do that so that ‘Event Tick’ would register the value for this interval. Afterwards, I reset the bool to false.
  2. In tick I call event ‘Update Sight’.
  3. In this event I used me macro ‘Bool Trigger’. This macro receives a bool variable (‘IsSeeingPlayer’ in our case) as input. The macro continues execution only if the input value changed in comparison with previous run. For example, if previously the input was true, and now it is false, ‘False Exec’ will fire. It is vice versa with ‘false’ → ‘true’. In case the value remains same, it stops executing. All in all, it is similar to ‘DoOnce’ macro with branch notifying that the value changed plugged into ‘Reset’ pin.
    I use this macro to tell whether the sight status of the player has changed this frame . If so, I can perform my logic, depending on whether the AI stopped or started seeing the player.
  4. Here I apply my code for the macro. I also added input ‘Skip first’ to avoid the situation when the macro continues execution when called for the 1st time. It is similar to ‘Start closed’ pin in ‘DoOnce’ macro.

    image
    image

I suppose you can turn off the PawnSensing Component

I just used a sphere collider and set its range to a value wanted the player to still be detected and used the Event “on component end overlap” to tell it to stop lol