Need some help with OnPerceptionUpdated's sensed actors

Hey, i’m working a bit with an AI for my game but i have gotten a bit stuck when it comes to the perception of actors for my AI.

I currently have three actors that are attached to the player character which are registered for sight stimuli and i want the AI to know how many of these three actors are in sight at all time. It looks something like this when the player is standing in view of the AI.


But the issue i’m currently having is that i can’t figure out how to get so that the AI knows how many of these are in view. The reason i cannot figure this out is because my OnPerceptionUpdated function’s sensed actors sometimes does not register the three actors it seems. When i’m walking around in the view of the AI and walk behind certain things the sensed actors array show weird values, for example when i’m standing in full view the sensed actors array is showing that it has 1 value.

PerceptionComp->OnPerceptionUpdated.AddDynamic(this, &AMurdererController::AISense);

void AMurdererController::AISense(TArray<AActor*> SensedActors)
{
	TempInt = SensedActors.Num(); (Printed out from Tick())
}

Anyone have any idea how i can go about doing so that the AI knows how many of the three actors that are attached to the player is in view. How i want to do is that the AI should go through the sensed actors array and maybe check if it finds any of the three actors and that it was WasSuccessfullySensed().

It’s a while since I played around with the perception component, but from what I remember, the array passed into the update event is not a list of actors currently sensed. I think it’s a list of actors whose perception state has just changed. So I believe you need to maintain your own list of currently perceived actors by checking the last stimulus information for each actor passed into the update delegate, and marking them as perceived/not perceived based on whether the last stimulus was a successful sensing.

I know Mieszko intended to change how this worked however and I haven’t kept up to date with it, so I’m not certain what the current situation is.

Ok, that is most likely the reason why the array num is sometimes off.

Correct me if i’m thinking incorrectly, but what you are suggesting is having my own array of actors that are currently successfully sensed? And that i would do this by adding/removing actors to this array in the OnPerceptionUpdated function dependent on if they were succesfully sensed or not?

That’s right. I believe the perception component is designed to just give information on received stimuli. It’s up to you to decide how you want to combine the stimuli from different senses, or over a period of time, to generate a higher level measure and memory of what your AI is aware of. Adding to/removing from an array as you outline would be the most basic approach to doing that.

Ok, thanks!