However, it appears that the enemy AI will not move towards the sound. Below are screenshots of blueprint code and AI Perception and I will explain what each part does for better understanding.
First, the enemy AI is spawned into the level and begins to randomly roam around the level:
I generate a Report Noise Event when I fire my pistol. This code is on my player, and the max range is currently 0.0 for testing purposes so the AI can hear it no matter how far away it is:
When a sound is heard, it’s supposed to interrupt the patrolling code, move to the location of the sound, “investigate” it for 3 seconds, then go back to patrolling:
In the YouTube video comments, there was a suggestion that I used to try to fix this but it did not work as intended. Either I didn’t set it up right or it truly doesn’t work, but I’ll leave what they said down below as well just in case it can help:
"If your AI doesnt go to the sound location you can follow these steps:
In your AI random roam Node. The first node you need put boolean “Investigating?”-> add Branch, add custom event called “Investigate sound”, and connect false to another branch for boolean “Is chasing”
On perception update : In AI move to at success node → delay node → set boolean “Is Investigating?” to false
Connect custom event “Investigate sound” to the first node at the same line from “On perception update”"
If you need more information, please let me know. Any help is appreciated, as I really would like to get this working!
Anyway, do you fully understand how the NOISE EVENT works? I don’t (I mean, I do, but I don’t know what all the nodes mean, specifically; I’d have to test them), and I always create my own events from scratch, because if you try to get creative or don’t fully understand how these functions work, they’ll break.
The first suggestion:
Is the CPU/ENEMY detecting the noise? In your THIRD SLIDE, attach to the FAIL condition in the BRANCH a PRINT STRING node. If it fires with the input string text, you have your issue. If not, let me/us know.
Unfortunately, as I am still relatively new to Unreal Engine, I regret to say that I do not fully understand how the Noise Event works. You might be right in the fact that something’s breaking due to me not fully understanding how it works. I’ll probably have to refer to the Noise Event documentation when I get the chance to.
I have attached the Print String node to the branch as suggested:
What’s interesting is that the string doesn’t print, so I don’t think the AI is even detecting it in the first place. Even when I’m right next to the enemy and firing the gun, it still doesn’t print anything.
Unfortunately, nothing is printed, even when firing right next to the enemy, so I wonder if it’s maybe the noise event that’s having an issue? Or if the way I’ve set up my AI Perception is incorrect?
I’m working on my own project, so I missed this detail:
Okay, let’s test the GET_SOCKET_LOCATION function. Place a PRINT_STRING node between PLAY_SOUND_AT_LOCATION and REPORT_NOISE_EVENT, making sure to plug in the output return value of GET_SOCKET_LOCATION into the input text pin of the PRINT_STRING.
Let’s see if that location prints. (Unless you already did that?)
It’s all good, I do appreciate you helping me out especially when you have your own project to focus on! I have not actually set up printing the socket location before this message, so I did it just now (apologies for the slight wire mess):
So good news: the socket location is being printed with the X, Y, and Z values every time I click my left mouse as shown here:
The different values are just because my player is moving around while shooting, so the socket is being detected.
I noticed in yours that you actually had your Dominant Sense set to AIHearing whereas I did not. I tested to see if maybe that makes a difference with the Dominant Sense set to AIHearing but unfortunately it appears that it does not. Does that matter if I already have an AI Hearing Config set in the Sense Config array?
The instigating actor (the one I assume is making the noise) should be the player. The sensing actor (the one “hearing” the sound) is the enemy and should be BP_ParasiteAI.
The Investigating Noise code is inside of BP_ParasiteAI and the Report Noise Event node is inside of the player BP. I don’t think I made “what code goes where” clear enough so hopefully that bit of information helps!
After looking at your advice, I did realize I hadn’t set an instigator on the Report Noise Event, but now it’s set here as the player character that shot the gun:
Now my enemy AI can detect a gun shot and it’s roam code is interrupted and the AI will check out the source of the noise! Thank you so much for your help!