How do I set the max age of a sense config?

So i’ve got an AI controller with both a sight and hearing sense config all set up.

The issue is that, in doing these tasks in blueprint, you can easily set the max age of the sense along with the other variables (peripheral vision, hearing range, etc) in the component details.

For some reason, and if I’m being completely dense point that out, I can’t set the max age along with my other sense config variables in C++ along with the others as it’s protected.

Here’s the code from my AI controller constructor, everything works perfectly, except the actors sensed never expire.

SightConfig->SightRadius = 750.0f;
	SightConfig->LoseSightRadius = 1000.0f;
	SightConfig->PeripheralVisionAngleDegrees = 90.0f;
	SightConfig->DetectionByAffiliation.bDetectEnemies = true;
	SightConfig->DetectionByAffiliation.bDetectFriendlies = true;
	SightConfig->DetectionByAffiliation.bDetectNeutrals = true;

	HearingConfig->HearingRange = 1500.0f;
	HearingConfig->LoSHearingRange = 2000.0f;
	HearingConfig->DetectionByAffiliation.bDetectEnemies = true;
	HearingConfig->DetectionByAffiliation.bDetectFriendlies = true;
	HearingConfig->DetectionByAffiliation.bDetectNeutrals = true;


	PerceptionComponent->OnPerceptionUpdated.AddDynamic(this, &ABasicPatrollerController::OnActorSensed);

So I ended up overriding the sense configs that I needed and adding a function to change the value from within the class. Not sure if this is intentional or not, feedback would be greatly appreciated.

Hi Skuvnar,

You can actually set the MaxAge of a UAISenseConfig by calling the SetMaxAge() function. For instance, you can wirte :
SightConfig->SetMaxAge(5.0f) if you want a sight stimulus to last for 5 seconds.

Be aware though that if you retrieve and store a stimulus via the OnTargetPerceptionUpdated method, the FAIStimulus is given by copy so you’ll need to manually update the age of your stored stimulus (for example in the Tick method or with a BTService node in your Behavior Tree - if you’re using one).

Hope this helps !