(AI Perception) Hearing not returning to fail when out of range

Hello All,

I’ve been working on my project where I want to focus on the most important senses, being sight and hearing. Everything is working perfectly so far, other than the hearing sense. I cannot get it to work properly and I’ve spent so much time trying to find a resolve, but to no avail.

Basically, the hearing doesn’t return to fail when I get out of it’s range. I’ve copied the blueprint for the sight over to the hearing and I just don’t understand why it isn’t failing. It detects me fine, as does the sight. Does anyone have a solution to this as I am running on fumes now with my determination to finish this project, as I’ve spent so much time trying to figure this out. Any help is greatly appreciated.

Hi,

You may need to set a Max Age in your Perception Component.

Also, once the the AI has loss sense, you should update your keys accordingly.

Hope this helps…

Many thanks for the response. Yeah, I did try that out before with the max age, though that didn’t give the intended result and muddled things up a bit. I left it at 0 and it has worked best with that value. All the ‘Detection by Affiliation’ boxes are set to true, which thankfully lets the AI detect me as can be seen in the video. It’s just making the AI not hear me when I am out of range that is making me scratch my head. When I connect the true and fail part of the branch for the hearing, on some occasions it goes to fail and it inspects the last heard location. However, when it hears me again, it follows me no matter how far away I am.

The blueprint you have as a example, works based upon the sense losing detection of the player. However, my issue is that the hearing doesn’t want to lose the hearing sense of the player. As you see in the video I have linked, the heard sense stays on true no matter what, even when I am out of range. The sight works as it should and goes to fail when not in view, so unfortunately the blueprint you sent doesn’t help in this case. I did try it out, though it isn’t of use due to the mentioned issue. Regardless, thanks for the information.

Just an update, but I’ve come across an interesting result when I removed the ‘branch’ and the ‘break ai stimulus’ from the blueprint and connected the hearing stimulus directly to the bool value. The hearing is detected as expected when in range, and when I get out of range it fails. However, it only fails when the AI sees me. At least it’s one step closer, though it isn’t the result I hope for. Regardless, maybe there is something I am not seeing that any of you can pick up on.

Attached you will find a screenshot of the old and new blueprint.

Perhaps instead of Get Actor Location to update Last Heard Location, try this…
Create a Variable for the Character and use Set Value as Object and pass the Character Variable as the Value.
Create a BB key called “Target” and set it to Object (Actor) then do a Move To “Target” in your BTree with a Decorator Is Set to “Target”.
Then back in your AIController, just create a branch and when False, you can set Character Variable to null.

You can change the “Target” name whatever…
You may need to cast to your actual character as the variable if the generic character won’t work.
Give it a shot…

I tested it, it works on my end.

Don’t forget to abort in your decorator.

Just to update the situation with this project. I have done a print string to see the range that the AI can hear me and it works perfectly when I just have the print string active. However, when I connect the boolean to the string for ‘Player Is Heard’, it stays true and doesn’t go back to false, even though the print string shows otherwise. The last heard location works great when I force the hearing to fail, so that part is ok. In the end, it is just trying to make the boolean go back to false when I am out of range that is the issue. I am not sharing the boolean name with anything else for the hearing, so I cannot see why it stays true. Though I’m not aware if there are any hidden settings which I have to adjust which may rememdy this issue.

Succesful blueprint with print string:

Same blueprint with boolean included

I have also done a version where the boolean isn’t connected to the ‘AISense_Hearing’ and has the box ticked to true to reflect the result from the condition of the branch, but again it gives the same results as the one you see in the image.

Just to update this thread and possibly assist others in my progress. I have tried other methods to try and solve the issue, such as creating a ‘Register for Sense’ and ‘Unregister for Sense’ in the player’s blueprint by pressing the H button. Unfortunately, this doesn’t solve the issue even though it shows where I was last heard. The AI keeps following me and doesn’t go back to fail with the bool. Print string works fine and it stops posting when I release the H button, which still baffles me as to why the bool doesn’t reflect the same response.

I’ll continue with my search for a solution and I’ll be updating this thread with my progress. Again, any help is welcome to solve this issue.

Hi, for your original question

Basically, the hearing doesn’t return
to fail when I get out of it’s range.

that is just how it works, there is no logic there that will do that. All it is doing inside the update is loop through the new noise stimuli and trigger a noise event for all listener that are in range and where the team is correct. In other words, you will never get a successfully sensed being false due to out of range. Then since you have set max age to 0 that means it will never forget any heared stimulus and therefore never get a successfully sensed being false due to age.

So think of the hearing sense as one shot events, it does not keep track of what it hears. Sight sense tracks all actors that have a stimuli source for sight constantly (with a limit on how much work it does per update, so it will update slower if you have too many sources and listener) which makes it somewhat heavy on performance but it will update constantly. Hearing is just a one shot event.


In

beantwortet Apr 29 '21 um 4:36 PM

in your “new” what you have done there is setting Player_Is_Heard to true if the stimulus came from hearing and set it to false if the stimulus came from any other sense (e. g. sight) which will lead to unpredictable behavior and is no solution to what you want.


What you could do is set the max age for the hearing sense to some value and then constantly (e. g. on timer) call new ReportNoiseEvents. Then if it gets out of range, after max age time it will give you an update with successfully sensed being false.

Many thanks for the post chrudimer. This is exactly what I wanted to know and I’ve made progress with my project as a result. I always thought hearing perception worked the same as the sight perception, which is what I was doing wrong.

I’m going to continue testing out my project, but a work around I found was to put a delay at the end of true branch for the hearing with different lengths of time (such as 0.5). After that, I copy and pasted the bool value but to be marked as fail for ‘Player_Is_Heard’ on the true branch (screenshot below). At the time of writing, this is doing the trick and is working as I want it to. I’m going to continue working on the last heard location aspect which shouldn’t be anything I can’t handle. If there are no crashes or anything large performance issues while I play it, I’ll mark this as the answer to my question. Many thanks once again.