Enemy AI will not move towards noise event

I have an enemy AI that currently patrols around the area, and when the enemy hears a noise through the Report Noise Event, I’d like the patrol to be interrupted and investigate the noise. I’ve followed along with this tutorial to try to achieve this effect: https://www.youtube.com/watch?v=w0t75DdkazU&list=PLQN3U_-lMANNM8VB9jLD13_wAxWlOqVH2&index=8

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:

This is my AI Perception, and it’s using the AISense_Hearing implementation:

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:

  1. 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”
  2. On perception update : In AI move to at success node → delay node → set boolean “Is Investigating?” to false
  3. 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!

Thank you for being so CLEAR with your issue!

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.

Thank you for your response!

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.

1 Like

Got it.

Then I would insert a PRINT STRING between the CAST and the ON TARGET PERCEPTION, as well as a PRINT STRING on the FAIL CONDIOTION of the CAST node.

I’ve set up the Print String nodes as follows:

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?

Okay, this is a “good” sign.

Now you know WHY this issue is happening.

What is the value for the target perception? It should be HEARING.

Yes, the target perception value is set to hearing, as shown below:

My mistake, you showed me that already.

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:

image

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?

I don’t know!

Ha. I don’t use this system.

Also, I just noticed, your output actor is BP_ParasiteAI. Is this the instigating actor or the sensing actor?

It looks like you reversed their roles, because if BP_ParasiteAI is the enemy, you’re telling your player character to move, not the enemy.

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!

I took a close look at the ON_TARGET_PERCEPTION_UPDATED node:

If I’m understanding it correctly, the output “Actor” is the actor that is instigating the sound, not sensing it.

Right now you are declaring that the enemy is the source of the sound.

You may also want to populate the “Instigator” pin in the REPORT_NOISE_EVENT, just to have your bases covered.

Again, this is an in-house function not fully understood by me.

1 Like

You’re literally a genius.

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:

And you were also right, I needed to change the cast from BP_ParasiteAI to my player BP:

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!

1 Like

:sweat_smile:

1 Like

Seriously, thank you. I do appreciate your help with this!

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.