AI perception component Max Age not working?

Hello,

In the project I’m working on, I currently use PawnSensingComponent for AI perception. I’m recently working on advanced AI behaviors and I wanted to try the newer AIPerceptionComponent.

I got the new component working, but it seems something is wrong when I try to get known perceived actor through GetKnownPerceivedActors, in blueprint.
I set a max age in the AI Perception configuration panel so when the target goes out of range, stimulus will expire after that time.

The problem is, if I set a sense to use in that node, AISense_Sight in my test, AI continues to perceive actors when it shouldn’t (target out of range).

The max age parameter seems to work only if I leave “sense to use” to none in GetKnownPerceivedActors node.

I also tried to add a AIPerceptionStimuliSource to the target player, which I’m not currently sure whether is necessary or not by the way, but this didn’t solve the issue.
I tried to setup a basic C++ third person template project from scratch to make sure the problem is not in my project, but the problem is still there.
The setup is really simple, I just duplicated the ThirdPersonCharacter, assigned it the AIPerception component and dropped in in the level.

This screenshot shows the setup for that AI.

I started investigating in the source, in the GetKnownPerceivedActors C++ function:

void UAIPerceptionComponent::GetKnownPerceivedActors(TSubclassOf<UAISense> SenseToUse, TArray<AActor*>& OutActors) const
{
	const FAISenseID SenseID = UAISense::GetSenseID(SenseToUse);

	OutActors.Reserve(PerceptualData.Num());
	for (FActorPerceptionContainer::TConstIterator DataIt = GetPerceptualDataConstIterator(); DataIt; ++DataIt)
	{
		const bool bWasEverPerceived = (SenseToUse == nullptr) ? DataIt->Value.HasAnyKnownStimulus() : DataIt->Value.HasKnownStimulusOfSense(SenseID);
		if (bWasEverPerceived)
		{
			if (DataIt->Value.Target.IsValid())
			{
				OutActors.Add(DataIt->Value.Target.Get());
			}
		}
	}
}

specifically, I guess the inlined function that runs when a specific sense to use is set returns true when it shouldn’t?

FORCEINLINE bool HasKnownStimulusOfSense(FAISenseID Sense) const
	{
		return LastSensedStimuli.IsValidIndex(Sense) && (LastSensedStimuli[Sense].GetAge() < FAIStimulus::NeverHappenedAge);
	}

This happens in both 4.18.3 and 4.19.1 versions.

Am I doing something wrong?
Thanks in advance!

doomtrinity

==================================

[UPDATE]

In the test project I accidentally added the component to the Character instead of AIController, but the problem occurs even with the component in the Controller class.

Hello, did you solve the problem with the max age?. I`m having the same problem and I am stuck.

Hi, I haven’t investigated further yet, because I don’t need this feature anymore, I’m sorry (please remember to comment instead of answer if you don’t have a solution).

Also dealing with this problem.

Did you check Forget Stale Actors in project settings?