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.
asked Jun 28 '16 at 07:51 AM in Blueprint Scripting
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!:)
Heres a picture to illustrate what I mean Hope it helps!
answered Sep 18 '16 at 11:13 PM
Sorry, must've forgotten the reset sense bit! Also this is going to be really long but bear with me:)
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. ![alt text]
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 : /storage/temp/108456-seeing+reset.png : /storage/temp/108458-stopchase.png
answered Sep 25 '16 at 11:40 PM
Mate, thankyou for this, works just like I wanted
answered Jan 18 '17 at 07:18 AM
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
answered May 30 '19 at 08:16 PM
Follow this question
Once you sign in you will be able to subscribe for any updates here