These are my blueprints that hold the logic, do you see anything strange?
Hi all, I am using AI perception in order to change AI Stances from passive to investigating.
The thing is that I have a Hearing test that “makes noise” on begin play. The enemy hears the sound correctly and investigates the location. Okay, then the enemy goes to Passive Stances again and starts patrolling, but instantly goes to investigating again. I debugged and it seems like the AI perception is hearing again the noise even if I did not shoot the noise again.
And this loops, the AI will never repatrol, cause when it trys, senses the hearing noise and keeps investigating the same location.
Does anyone know why I have constantly percepting the same noise even if I only shoot it once?
Hi, can you show images of the relevant code parts (AI perception logic, hearing sense config and behavior tree) ?
If you only call one noise event, then it will only perceive one. Without seeing the acutal code my guess is that you either call it constantly, not setting your blackboard values correctly from the AI perception and/or not having the hearing sense config setup correctly in conjunction with how you set the blackboard values (e. g. if you set MaxAge to 0, then SuccessfullySensed will always be true, it will never become false).
Since you’re looping through all LastSensedStimuli you’re calling HeardSomething everytime something changes in this actors perception (so every time it starts seeing this actor or stops seeing it, hears it or stops hearing it and same for all other senses you might have setup there). Also you’re never checking for SuccessfullySensed being true, so whether it can actually hear that actor (or has ever heard it) or not. If it has never heard that actor, then the StimulusLocation will be some random garbage value.
Then since you’re grabbing the latest hearing stimulus, that means that if the latest hearing stimulus had a RunnerStimuli tag, then you will call RunnerStateChanged to Warning and if that is what your blackboard condition is checking for, then you will execute that behavior tree branch you’ve shown in the image.
So what you need to change at least, is in HeardSomething check for SuccessfullySensed being true. Also depending on how you want to use/setup the perception logic, you could consider using OnTargetPerceptionUpdated instead of OnPerceptionUpdated. The difference there is that OnTargetPerceptionUpdated will give you the stimulus that has changed (so that you could then only execute HeardSomething if the update was actually triggered by the hearing sense and not any other sense).
Branching “SuccesfullySensed” worked but now Im curious about “OnTargetpercepctionUpdated” but don’t know if I understand it very well how it works and how should I use it.
OnPerceptionUpdated gives you an array of actors whose perception has changed. OnTargetPerceptionUpdated gets called once for each of those actors and gives you the actor and the new stimulus. That means that in your image, if you would replace OnPerceptionUpdated and the ForEachLoop with OnTargetPerceptionUpdated and plug the actor from it into GetActorsPerception you would get the exact same result as what you’re currently doing. Only that you’re now also getting the stimulus that triggered the update, so you can check which sense triggered that update.
I think I understand. Thanks for your help, now the AI works exactly how I needed.